import {
  UnlockPrivateResponseSchema,
  type UnlockPrivateReason,
  type UnlockPrivateResponseData,
  type UnlockPrivateResponseInput,
} from "@/data/schemas/chat/response/unlock_private_response";
import type { ChatImageData, ChatLockType } from "@/data/schemas/chat";

/**
 * 单条历史付费 / 私密消息解锁响应 DTO。
 */
export class UnlockPrivateResponse {
  declare readonly unlocked: boolean;
  declare readonly messageId: string;
  declare readonly clientLockId: string | null;
  declare readonly lockType: ChatLockType | null;
  declare readonly content: string;
  declare readonly audioUrl: string;
  declare readonly image: ChatImageData;
  declare readonly reason: UnlockPrivateReason;
  declare readonly creditBalance: number;
  declare readonly creditsCharged: number;
  declare readonly requiredCredits: number;
  declare readonly shortfallCredits: number;

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

  static from(input: UnlockPrivateResponseInput): UnlockPrivateResponse {
    return new UnlockPrivateResponse(input);
  }

  static fromJson(json: unknown): UnlockPrivateResponse {
    return UnlockPrivateResponse.from(json as UnlockPrivateResponseInput);
  }

  toJson(): UnlockPrivateResponseData {
    return UnlockPrivateResponseSchema.parse(this);
  }
}
