import { AggregateRoot } from '@nestjs/cqrs'; export class DailyActiveStats extends AggregateRoot { private _day: Date; private _dauCount: number; private _dauByProvince: Map; private _dauByCity: Map; private _calculatedAt: Date; private _version: number; private constructor() { super(); } get day(): Date { return this._day; } get dauCount(): number { return this._dauCount; } get dauByProvince(): Map { return new Map(this._dauByProvince); } get dauByCity(): Map { return new Map(this._dauByCity); } get calculatedAt(): Date { return this._calculatedAt; } get version(): number { return this._version; } static create(props: { day: Date; dauCount: number; dauByProvince?: Map; dauByCity?: Map; }): DailyActiveStats { const stats = new DailyActiveStats(); stats._day = props.day; stats._dauCount = props.dauCount; stats._dauByProvince = props.dauByProvince ?? new Map(); stats._dauByCity = props.dauByCity ?? new Map(); stats._calculatedAt = new Date(); stats._version = 1; return stats; } recalculate(newDauCount: number, byProvince?: Map, byCity?: Map): void { this._dauCount = newDauCount; if (byProvince) this._dauByProvince = byProvince; if (byCity) this._dauByCity = byCity; this._calculatedAt = new Date(); this._version++; } static reconstitute(props: { day: Date; dauCount: number; dauByProvince: Map; dauByCity: Map; calculatedAt: Date; version: number; }): DailyActiveStats { const stats = new DailyActiveStats(); stats._day = props.day; stats._dauCount = props.dauCount; stats._dauByProvince = props.dauByProvince; stats._dauByCity = props.dauByCity; stats._calculatedAt = props.calculatedAt; stats._version = props.version; return stats; } }