/**
 * 应用事件上报请求 DTO
 */
import {
  AppEventSchema,
  type AppEventInput,
  type AppEventData,
} from "@/data/schemas/metrics/app_event";

export class AppEvent {
  declare readonly userId: string;
  declare readonly browser: string;
  declare readonly userAgent: string;

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

  static from(input: AppEventInput): AppEvent {
    return new AppEvent(input);
  }

  static fromJson(json: unknown): AppEvent {
    return AppEvent.from(json as AppEventInput);
  }

  toJson(): AppEventData {
    return AppEventSchema.parse(this);
  }
}
