import { Answer } from '../enums/answer.enum'; import { User } from './user.model'; export class Choice { constructor( public label: string, public imageUrl?: string, public participants: Map> = new Map>([ [Answer.YES, new Set()], [Answer.NO, new Set()], [Answer.MAYBE, new Set()], ]), public counts: Map = new Map([ [Answer.YES, 0], [Answer.NO, 0], [Answer.MAYBE, 0], ]) ) {} public updateParticipation(user: User, responseType: Answer): void { this.removeParticipant(user); this.participants.get(responseType).add(user); this.updateCounts(); } public removeParticipant(user: User): void { for (const responseType of Object.values(Answer)) { if (this.participants.get(responseType).has(user)) { this.participants.get(responseType).delete(user); } } } public updateCounts(): void { for (const responseType of Object.values(Answer)) { this.counts.set(responseType, this.participants.get(responseType).size); } } }