/*
 * 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";

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

/**
 * Create a subscription for an existing customer.
 */
export type SubscriptionCreateCustomer = {
  /**
   * 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;
  /**
   * The ID of the recurring product to subscribe to. Must be a free product, otherwise the customer should go through a checkout flow.
   */
  productId: string;
  /**
   * The ID of the customer to create the subscription for.
   */
  customerId: string;
};

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

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

export function metadataToJSON(metadata: Metadata): string {
  return JSON.stringify(Metadata$outboundSchema.parse(metadata));
}

/** @internal */
export type SubscriptionCreateCustomer$Outbound = {
  metadata?: { [k: string]: string | number | number | boolean } | undefined;
  product_id: string;
  customer_id: string;
};

/** @internal */
export const SubscriptionCreateCustomer$outboundSchema: z.ZodMiniType<
  SubscriptionCreateCustomer$Outbound,
  SubscriptionCreateCustomer
> = z.pipe(
  z.object({
    metadata: z.optional(
      z.record(
        z.string(),
        smartUnion([z.string(), z.int(), z.number(), z.boolean()]),
      ),
    ),
    productId: z.string(),
    customerId: z.string(),
  }),
  z.transform((v) => {
    return remap$(v, {
      productId: "product_id",
      customerId: "customer_id",
    });
  }),
);

export function subscriptionCreateCustomerToJSON(
  subscriptionCreateCustomer: SubscriptionCreateCustomer,
): string {
  return JSON.stringify(
    SubscriptionCreateCustomer$outboundSchema.parse(subscriptionCreateCustomer),
  );
}
