import { TimeWindow } from '../value-objects/time-window.vo';

export class OnlineSnapshot {
  private _id: bigint | null;
  private _ts: Date;
  private _onlineCount: number;
  private _windowSeconds: number;

  private constructor() {}

  get id(): bigint | null { return this._id; }
  get ts(): Date { return this._ts; }
  get onlineCount(): number { return this._onlineCount; }
  get windowSeconds(): number { return this._windowSeconds; }

  static create(props: { ts: Date; onlineCount: number; windowSeconds?: number }): OnlineSnapshot {
    const snapshot = new OnlineSnapshot();
    snapshot._id = null;
    snapshot._ts = props.ts;
    snapshot._onlineCount = props.onlineCount;
    snapshot._windowSeconds = props.windowSeconds ?? TimeWindow.DEFAULT_ONLINE_WINDOW_SECONDS;
    return snapshot;
  }

  static reconstitute(props: { id: bigint; ts: Date; onlineCount: number; windowSeconds: number }): OnlineSnapshot {
    const snapshot = new OnlineSnapshot();
    snapshot._id = props.id;
    snapshot._ts = props.ts;
    snapshot._onlineCount = props.onlineCount;
    snapshot._windowSeconds = props.windowSeconds;
    return snapshot;
  }
}
