/*
 * 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 {
  SubscriptionProrationBehavior,
  SubscriptionProrationBehavior$outboundSchema,
} from "./subscriptionprorationbehavior.js";

export type SubscriptionUpdateBase = {
  /**
   * Update subscription to another product.
   */
  productId?: string | null | undefined;
  /**
   * Determine how to handle the proration billing. If not provided, will use the default organization setting.
   */
  prorationBehavior?: SubscriptionProrationBehavior | null | undefined;
  /**
   * Update the subscription to apply a new discount. If set to `null`, the discount will be removed. The change will be applied on the next billing cycle.
   */
  discountId?: string | null | undefined;
  /**
   * Set or extend the trial period of the subscription. If set to `now`, the trial will end immediately.
   */
  trialEnd?: Date | null | undefined;
};

/** @internal */
export type SubscriptionUpdateBase$Outbound = {
  product_id?: string | null | undefined;
  proration_behavior?: string | null | undefined;
  discount_id?: string | null | undefined;
  trial_end?: string | null | undefined;
};

/** @internal */
export const SubscriptionUpdateBase$outboundSchema: z.ZodMiniType<
  SubscriptionUpdateBase$Outbound,
  SubscriptionUpdateBase
> = z.pipe(
  z.object({
    productId: z.optional(z.nullable(z.string())),
    prorationBehavior: z.optional(
      z.nullable(SubscriptionProrationBehavior$outboundSchema),
    ),
    discountId: z.optional(z.nullable(z.string())),
    trialEnd: z.optional(
      z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))),
    ),
  }),
  z.transform((v) => {
    return remap$(v, {
      productId: "product_id",
      prorationBehavior: "proration_behavior",
      discountId: "discount_id",
      trialEnd: "trial_end",
    });
  }),
);

export function subscriptionUpdateBaseToJSON(
  subscriptionUpdateBase: SubscriptionUpdateBase,
): string {
  return JSON.stringify(
    SubscriptionUpdateBase$outboundSchema.parse(subscriptionUpdateBase),
  );
}
