/** * 一键解锁历史锁定消息响应 */ import { z } from "zod"; import { arrayOrEmpty, booleanOrFalse, numberOrZero, recordOrEmpty, } from "../../nullable-defaults"; export const UnlockHistoryCostsByMessageSchema = recordOrEmpty(z.number()); export const UnlockHistoryReasonSchema = z.enum([ "ok", "insufficient_balance", "no_locked_messages", ]); export const UnlockHistoryResponseSchema = z.object({ unlocked: booleanOrFalse, reason: UnlockHistoryReasonSchema, totalLocked: numberOrZero, unlockedCount: numberOrZero, privateCount: numberOrZero, imageCount: numberOrZero, voiceCount: numberOrZero, requiredCredits: numberOrZero, currentCredits: numberOrZero, remainingCredits: numberOrZero, shortfallCredits: numberOrZero, costsByMessage: UnlockHistoryCostsByMessageSchema, messageIds: arrayOrEmpty(z.string()), }); export type UnlockHistoryReason = z.output; export type UnlockHistoryResponseInput = z.input< typeof UnlockHistoryResponseSchema >; export type UnlockHistoryResponseData = z.output< typeof UnlockHistoryResponseSchema >; export class UnlockHistoryResponse { declare readonly unlocked: boolean; declare readonly reason: UnlockHistoryReason; declare readonly shortfallCredits: number; 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); } }