import { Answer } from '../enums/answer.enum'; import { Owner } from './owner.model'; export class ChoiceGroup { date_string: string; subSetToYes = false; // to know if all the choices are set to YES, to toggle them all at once without checking them individually choices: Choice[]; } export class AnswerStats { count: number; people: Array; } export class Choice { public id: number; public name: string; public created_at: string; public score: number; public enabled: boolean; public url?: string; public yes?: AnswerStats; public no?: AnswerStats; public maybe?: AnswerStats; constructor( 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: Owner, responseType: Answer): void { this.removeParticipant(user); this.participants.get(responseType).add(user); this.updateCounts(); } public removeParticipant(user: Owner): 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); } } }