export interface Clock {
  nowMs(): number;
  nowIso(): string;
}

export class SystemClock implements Clock {
  nowMs(): number {
    return Date.now();
  }
  nowIso(): string {
    return new Date(this.nowMs()).toISOString();
  }
}

/** Deterministic clock for tests */
export class TestClock implements Clock {
  private _now: number;
  constructor(startMs: number = 0) {
    this._now = startMs;
  }
  nowMs(): number {
    return this._now;
  }
  nowIso(): string {
    return new Date(this._now).toISOString();
  }
  advanceMs(deltaMs: number): void {
    this._now += deltaMs;
  }
  setMs(ms: number): void {
    this._now = ms;
  }
}
