/**
 * PWA 事件上报请求 DTO
 */
import {
  PwaEventSchema,
  type PwaEventInput,
  type PwaEventData,
} from "@/data/schemas/metrics/pwa_event";

export class PwaEvent {
  declare readonly deviceId: string;
  declare readonly deviceType: string;
  declare readonly timestamp: number;
  declare readonly pwaInstalled: boolean;
  declare readonly pwaSupported: boolean;

  private constructor(input: PwaEventInput) {
    const data = PwaEventSchema.parse(input);
    Object.assign(this, data);
    Object.freeze(this);
  }

  static from(input: PwaEventInput): PwaEvent {
    return new PwaEvent(input);
  }

  static fromJson(json: unknown): PwaEvent {
    return PwaEvent.from(json as PwaEventInput);
  }

  toJson(): PwaEventData {
    return PwaEventSchema.parse(this);
  }
}
