/*
 * 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 { smartUnion } from "../../types/smartUnion.js";
import {
  AddressInput,
  AddressInput$Outbound,
  AddressInput$outboundSchema,
} from "./addressinput.js";

export type CheckoutUpdatePublicCustomFieldData =
  | string
  | number
  | boolean
  | Date;

/**
 * Update an existing checkout session using the client secret.
 */
export type CheckoutUpdatePublic = {
  /**
   * Key-value object storing custom field values.
   */
  customFieldData?:
    | { [k: string]: string | number | boolean | Date | null }
    | undefined;
  /**
   * ID of the product to checkout. Must be present in the checkout's product list.
   */
  productId?: string | null | undefined;
  /**
   * ID of the product price to checkout. Must correspond to a price present in the checkout's product list.
   *
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  productPriceId?: string | null | undefined;
  amount?: number | null | undefined;
  /**
   * Number of seats for seat-based pricing.
   */
  seats?: number | null | undefined;
  isBusinessCustomer?: boolean | null | undefined;
  customerName?: string | null | undefined;
  customerEmail?: string | null | undefined;
  customerBillingName?: string | null | undefined;
  customerBillingAddress?: AddressInput | null | undefined;
  customerTaxId?: string | null | undefined;
  locale?: string | null | undefined;
  /**
   * Discount code to apply to the checkout.
   */
  discountCode?: string | null | undefined;
  /**
   * Disable the trial period for the checkout session. It's mainly useful when the trial is blocked because the customer already redeemed one.
   */
  allowTrial?: false | null | undefined;
};

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

/** @internal */
export const CheckoutUpdatePublicCustomFieldData$outboundSchema: z.ZodMiniType<
  CheckoutUpdatePublicCustomFieldData$Outbound,
  CheckoutUpdatePublicCustomFieldData
> = smartUnion([
  z.string(),
  z.int(),
  z.boolean(),
  z.pipe(z.date(), z.transform(v => v.toISOString())),
]);

export function checkoutUpdatePublicCustomFieldDataToJSON(
  checkoutUpdatePublicCustomFieldData: CheckoutUpdatePublicCustomFieldData,
): string {
  return JSON.stringify(
    CheckoutUpdatePublicCustomFieldData$outboundSchema.parse(
      checkoutUpdatePublicCustomFieldData,
    ),
  );
}

/** @internal */
export type CheckoutUpdatePublic$Outbound = {
  custom_field_data?:
    | { [k: string]: string | number | boolean | string | null }
    | undefined;
  product_id?: string | null | undefined;
  product_price_id?: string | null | undefined;
  amount?: number | null | undefined;
  seats?: number | null | undefined;
  is_business_customer?: boolean | null | undefined;
  customer_name?: string | null | undefined;
  customer_email?: string | null | undefined;
  customer_billing_name?: string | null | undefined;
  customer_billing_address?: AddressInput$Outbound | null | undefined;
  customer_tax_id?: string | null | undefined;
  locale?: string | null | undefined;
  discount_code?: string | null | undefined;
  allow_trial?: false | null | undefined;
};

/** @internal */
export const CheckoutUpdatePublic$outboundSchema: z.ZodMiniType<
  CheckoutUpdatePublic$Outbound,
  CheckoutUpdatePublic
> = z.pipe(
  z.object({
    customFieldData: z.optional(
      z.record(
        z.string(),
        z.nullable(
          smartUnion([
            z.string(),
            z.int(),
            z.boolean(),
            z.pipe(z.date(), z.transform(v => v.toISOString())),
          ]),
        ),
      ),
    ),
    productId: z.optional(z.nullable(z.string())),
    productPriceId: z.optional(z.nullable(z.string())),
    amount: z.optional(z.nullable(z.int())),
    seats: z.optional(z.nullable(z.int())),
    isBusinessCustomer: z.optional(z.nullable(z.boolean())),
    customerName: z.optional(z.nullable(z.string())),
    customerEmail: z.optional(z.nullable(z.string())),
    customerBillingName: z.optional(z.nullable(z.string())),
    customerBillingAddress: z.optional(z.nullable(AddressInput$outboundSchema)),
    customerTaxId: z.optional(z.nullable(z.string())),
    locale: z.optional(z.nullable(z.string())),
    discountCode: z.optional(z.nullable(z.string())),
    allowTrial: z.optional(z.nullable(z.literal(false))),
  }),
  z.transform((v) => {
    return remap$(v, {
      customFieldData: "custom_field_data",
      productId: "product_id",
      productPriceId: "product_price_id",
      isBusinessCustomer: "is_business_customer",
      customerName: "customer_name",
      customerEmail: "customer_email",
      customerBillingName: "customer_billing_name",
      customerBillingAddress: "customer_billing_address",
      customerTaxId: "customer_tax_id",
      discountCode: "discount_code",
      allowTrial: "allow_trial",
    });
  }),
);

export function checkoutUpdatePublicToJSON(
  checkoutUpdatePublic: CheckoutUpdatePublic,
): string {
  return JSON.stringify(
    CheckoutUpdatePublic$outboundSchema.parse(checkoutUpdatePublic),
  );
}
