import {
  PrivateAlbumUnlockResponseSchema,
  type PrivateAlbumUnlockReason,
  type PrivateAlbumUnlockResponseData,
  type PrivateAlbumUnlockResponseInput,
} from "@/data/schemas/private-room";

export class PrivateAlbumUnlockResponse {
  declare readonly albumId: string;
  declare readonly locked: boolean;
  declare readonly unlocked: boolean;
  declare readonly reason: PrivateAlbumUnlockReason | string;
  declare readonly unlockCost: number;
  declare readonly requiredCredits: number;
  declare readonly creditBalance: number;
  declare readonly shortfallCredits: number;
  declare readonly images: PrivateAlbumUnlockResponseData["images"];

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

  static from(input: PrivateAlbumUnlockResponseInput): PrivateAlbumUnlockResponse {
    return new PrivateAlbumUnlockResponse(input);
  }

  static fromJson(json: unknown): PrivateAlbumUnlockResponse {
    return PrivateAlbumUnlockResponse.from(
      json as PrivateAlbumUnlockResponseInput,
    );
  }

  toJson(): PrivateAlbumUnlockResponseData {
    return PrivateAlbumUnlockResponseSchema.parse(this);
  }
}
