import { z } from "zod";

import { booleanOrFalse, numberOrZero, stringOrEmpty } from "../nullable-defaults";
import { PrivateRoomMomentSchema } from "./private_room";

export const PrivateRoomUnlockReasonSchema = z.enum([
  "ok",
  "already_unlocked",
  "insufficient_credits",
  "cost_changed",
  "not_found",
  "no_media",
  "deduct_failed",
  "ok_persist_failed",
]);

export const PrivateRoomUnlockResponseSchema =
  PrivateRoomMomentSchema.extend({
    reason: PrivateRoomUnlockReasonSchema.or(stringOrEmpty),
    creditsCharged: numberOrZero,
    creditBalance: numberOrZero,
    previousCreditBalance: numberOrZero,
    currentCredits: numberOrZero,
    shortfallCredits: numberOrZero,
    persisted: booleanOrFalse,
  });

export type PrivateRoomUnlockReason = z.output<
  typeof PrivateRoomUnlockReasonSchema
>;
export type PrivateRoomUnlockResponseInput = z.input<
  typeof PrivateRoomUnlockResponseSchema
>;
export type PrivateRoomUnlockResponseData = z.output<
  typeof PrivateRoomUnlockResponseSchema
>;
