import {
  PrivateRoomMomentSchema,
  type PrivateRoomMomentData,
  type PrivateRoomMomentInput,
} from "@/data/schemas/private-room";

export class PrivateRoomMoment {
  declare readonly momentId: string;
  declare readonly source: string;
  declare readonly sourceId: string;
  declare readonly characterId: string;
  declare readonly author: PrivateRoomMomentData["author"];
  declare readonly createdAt: string | null;
  declare readonly publishedAt: string | null;
  declare readonly timeText: string;
  declare readonly title: string;
  declare readonly content: string | null;
  declare readonly text: string | null;
  declare readonly textPreview: string;
  declare readonly mediaCount: number;
  declare readonly images: PrivateRoomMomentData["images"];
  declare readonly locked: boolean;
  declare readonly unlocked: boolean;
  declare readonly unlockCost: number;
  declare readonly unlockCostPerImage: number;
  declare readonly requiredCredits: number;
  declare readonly currency: string;
  declare readonly lockDetail: PrivateRoomMomentData["lockDetail"];

  protected constructor(input: PrivateRoomMomentInput, freeze = true) {
    const data = PrivateRoomMomentSchema.parse(input);
    Object.assign(this, data);
    if (freeze) Object.freeze(this);
  }

  static from(input: PrivateRoomMomentInput): PrivateRoomMoment {
    return new PrivateRoomMoment(input);
  }

  static fromJson(json: unknown): PrivateRoomMoment {
    return PrivateRoomMoment.from(json as PrivateRoomMomentInput);
  }

  toJson(): PrivateRoomMomentData {
    return PrivateRoomMomentSchema.parse(this);
  }
}

export type PrivateRoomProfile = import("@/data/schemas/private-room").PrivateRoomProfileData;
export type PrivateRoomImage = import("@/data/schemas/private-room").PrivateRoomImageData;
export type PrivateRoomLockDetail = import("@/data/schemas/private-room").PrivateRoomLockDetailData;
