import {
  PrivateAlbumSchema,
  type PrivateAlbumData,
  type PrivateAlbumInput,
} from "@/data/schemas/private-room";

export class PrivateAlbum {
  declare readonly albumId: string;
  declare readonly title: string;
  declare readonly content: string | null;
  declare readonly previewText: string;
  declare readonly imageCount: number;
  declare readonly images: PrivateAlbumData["images"];
  declare readonly locked: boolean;
  declare readonly unlocked: boolean;
  declare readonly unlockCost: number;
  declare readonly publishedAt: string | null;
  declare readonly lockDetail: PrivateAlbumData["lockDetail"];

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

  static from(input: PrivateAlbumInput): PrivateAlbum {
    return new PrivateAlbum(input);
  }

  static fromJson(json: unknown): PrivateAlbum {
    return PrivateAlbum.from(json as PrivateAlbumInput);
  }

  toJson(): PrivateAlbumData {
    return PrivateAlbumSchema.parse(this);
  }
}
