import {
  PrivateRoomUnlockResponseSchema,
  type PrivateRoomUnlockReason,
  type PrivateRoomUnlockResponseData,
  type PrivateRoomUnlockResponseInput,
} from "@/data/schemas/private-room";

import { PrivateRoomMoment } from "../private_room_moment";

export class PrivateRoomUnlockResponse extends PrivateRoomMoment {
  declare readonly reason: PrivateRoomUnlockReason | string;
  declare readonly creditsCharged: number;
  declare readonly creditBalance: number;
  declare readonly previousCreditBalance: number;
  declare readonly currentCredits: number;
  declare readonly shortfallCredits: number;
  declare readonly persisted: boolean;

  private constructor(input: PrivateRoomUnlockResponseInput) {
    const data = PrivateRoomUnlockResponseSchema.parse(input);
    super(data, false);
    Object.assign(this, data);
    Object.freeze(this);
  }

  static override from(
    input: PrivateRoomUnlockResponseInput,
  ): PrivateRoomUnlockResponse {
    return new PrivateRoomUnlockResponse(input);
  }

  static override fromJson(json: unknown): PrivateRoomUnlockResponse {
    return PrivateRoomUnlockResponse.from(
      json as PrivateRoomUnlockResponseInput,
    );
  }

  override toJson(): PrivateRoomUnlockResponseData {
    return PrivateRoomUnlockResponseSchema.parse(this);
  }
}
