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