import { z } from "zod";

import {
  booleanOrFalse,
  numberOrZero,
  stringOrEmpty,
  stringOrNull,
} from "../../nullable-defaults";
import { ChatLockTypeSchema } from "../chat_lock_type";
import { ChatImageSchema } from "../chat_payloads";
import { PaymentGuidanceSchema } from "./chat_send_response";

/**
 * 单条历史付费 / 私密消息解锁响应。
 */
export const UnlockPrivateReasonSchema = stringOrEmpty;

export const UnlockPrivateResponseSchema = z
  .object({
    unlocked: booleanOrFalse,
    content: stringOrEmpty,
    messageId: stringOrEmpty,
    clientLockId: stringOrNull,
    lockType: ChatLockTypeSchema.nullable().default(null),
    audioUrl: stringOrEmpty,
    image: ChatImageSchema,
    reason: UnlockPrivateReasonSchema,
    creditBalance: numberOrZero,
    creditsCharged: numberOrZero,
    requiredCredits: numberOrZero,
    shortfallCredits: numberOrZero,
    paymentGuidance: PaymentGuidanceSchema.nullish().default(null),
  })
  .readonly();

export type UnlockPrivateReason = z.output<typeof UnlockPrivateReasonSchema>;
export type UnlockPrivateResponseInput = z.input<
  typeof UnlockPrivateResponseSchema
>;
export type UnlockPrivateResponseData = z.output<
  typeof UnlockPrivateResponseSchema
>;

export type UnlockPrivateResponse = UnlockPrivateResponseData;
