/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v4-mini";
import { remap as remap$ } from "../../lib/primitives.js";
import { ClosedEnum } from "../../types/enums.js";
import { smartUnion } from "../../types/smartUnion.js";

export type RefundCreateMetadata = string | number | number | boolean;

/**
 * Reason for the refund.
 */
export const Reason = {
  Duplicate: "duplicate",
  Fraudulent: "fraudulent",
  CustomerRequest: "customer_request",
  ServiceDisruption: "service_disruption",
  SatisfactionGuarantee: "satisfaction_guarantee",
  Other: "other",
} as const;
/**
 * Reason for the refund.
 */
export type Reason = ClosedEnum<typeof Reason>;

export type RefundCreate = {
  /**
   * Key-value object allowing you to store additional information.
   *
   * @remarks
   *
   * The key must be a string with a maximum length of **40 characters**.
   * The value must be either:
   *
   * * A string with a maximum length of **500 characters**
   * * An integer
   * * A floating-point number
   * * A boolean
   *
   * You can store up to **50 key-value pairs**.
   */
  metadata?: { [k: string]: string | number | number | boolean } | undefined;
  orderId: string;
  /**
   * Reason for the refund.
   */
  reason: Reason;
  /**
   * Amount to refund in cents. Minimum is 1.
   */
  amount: number;
  /**
   * An internal comment about the refund.
   */
  comment?: string | null | undefined;
  /**
   * Should this refund trigger the associated customer benefits to be revoked?
   *
   * @remarks
   *
   * **Note:**
   * Only allowed in case the `order` is a one-time purchase.
   * Subscriptions automatically revoke customer benefits once the
   * subscription itself is revoked, i.e fully canceled.
   */
  revokeBenefits?: boolean | undefined;
};

/** @internal */
export type RefundCreateMetadata$Outbound = string | number | number | boolean;

/** @internal */
export const RefundCreateMetadata$outboundSchema: z.ZodMiniType<
  RefundCreateMetadata$Outbound,
  RefundCreateMetadata
> = smartUnion([z.string(), z.int(), z.number(), z.boolean()]);

export function refundCreateMetadataToJSON(
  refundCreateMetadata: RefundCreateMetadata,
): string {
  return JSON.stringify(
    RefundCreateMetadata$outboundSchema.parse(refundCreateMetadata),
  );
}

/** @internal */
export const Reason$outboundSchema: z.ZodMiniEnum<typeof Reason> = z.enum(
  Reason,
);

/** @internal */
export type RefundCreate$Outbound = {
  metadata?: { [k: string]: string | number | number | boolean } | undefined;
  order_id: string;
  reason: string;
  amount: number;
  comment?: string | null | undefined;
  revoke_benefits: boolean;
};

/** @internal */
export const RefundCreate$outboundSchema: z.ZodMiniType<
  RefundCreate$Outbound,
  RefundCreate
> = z.pipe(
  z.object({
    metadata: z.optional(
      z.record(
        z.string(),
        smartUnion([z.string(), z.int(), z.number(), z.boolean()]),
      ),
    ),
    orderId: z.string(),
    reason: Reason$outboundSchema,
    amount: z.int(),
    comment: z.optional(z.nullable(z.string())),
    revokeBenefits: z._default(z.boolean(), false),
  }),
  z.transform((v) => {
    return remap$(v, {
      orderId: "order_id",
      revokeBenefits: "revoke_benefits",
    });
  }),
);

export function refundCreateToJSON(refundCreate: RefundCreate): string {
  return JSON.stringify(RefundCreate$outboundSchema.parse(refundCreate));
}
