/**
 * 一键解锁历史锁定消息响应 DTO
 */
import {
  UnlockHistoryResponseSchema,
  type UnlockHistoryReason,
  type UnlockHistoryResponseData,
  type UnlockHistoryResponseInput,
} from "@/data/schemas/chat/unlock_history_response";

export class UnlockHistoryResponse {
  declare readonly unlocked: boolean;
  declare readonly reason: UnlockHistoryReason;
  declare readonly totalLocked: number;
  declare readonly unlockedCount: number;
  declare readonly privateCount: number;
  declare readonly imageCount: number;
  declare readonly voiceCount: number;
  declare readonly requiredCredits: number;
  declare readonly currentCredits: number;
  declare readonly remainingCredits: number;
  declare readonly shortfallCredits: number;
  declare readonly costsByMessage: Record<string, number>;
  declare readonly messageIds: string[];

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

  static from(input: UnlockHistoryResponseInput): UnlockHistoryResponse {
    return new UnlockHistoryResponse(input);
  }

  static fromJson(json: unknown): UnlockHistoryResponse {
    return UnlockHistoryResponse.from(json as UnlockHistoryResponseInput);
  }

  toJson(): UnlockHistoryResponseData {
    return UnlockHistoryResponseSchema.parse(this);
  }
}
