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

import * as z from "zod/v3";
import { remap as remap$ } from "../lib/primitives.js";
import { safeParse } from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { smartUnion } from "../types/smartUnion.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

/**
 * The type of item to purchase.
 */
export const BuyCreditsType = {
  Credits: "credits",
} as const;
/**
 * The type of item to purchase.
 */
export type BuyCreditsType = ClosedEnum<typeof BuyCreditsType>;

/**
 * The type of credits to purchase.
 */
export const CreditType = {
  V0: "v0",
  Gateway: "gateway",
  Agent: "agent",
} as const;
/**
 * The type of credits to purchase.
 */
export type CreditType = ClosedEnum<typeof CreditType>;

export type Item = {
  /**
   * The type of item to purchase.
   */
  type: BuyCreditsType;
  /**
   * The type of credits to purchase.
   */
  creditType: CreditType;
  /**
   * The amount of credits to purchase.
   */
  amount: number;
};

export type BuyCreditsRequestBody = {
  item: Item;
};

export type BuyCreditsRequest = {
  /**
   * The source of the purchase request. Defaults to `api` if not specified.
   */
  source?: string | undefined;
  /**
   * The Team identifier to perform the request on behalf of.
   */
  teamId?: string | undefined;
  /**
   * The Team slug to perform the request on behalf of.
   */
  slug?: string | undefined;
  requestBody: BuyCreditsRequestBody;
};

/**
 * Configuration input options for adjusting plan item quantity.
 */
export type BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3OrbSubscriptionIntentOptions =
  {
    /**
     * The resource IDs to incrementally add. The quantity of the plan item will be increased by the number of resource IDs.
     */
    addedResourceIds: Array<string>;
    /**
     * The alias of the product to adjust quantity for.
     */
    productAlias: string;
    /**
     * The resource IDs to incrementally remove. The quantity of the plan item will be decreased by the number of resource IDs.
     */
    removedResourceIds: Array<string>;
  };

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResourcesBillingResponse4 = {
  /**
   * Resource IDs that were added.
   */
  addedResourceIds: Array<string>;
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were removed.
   */
  removedResourceIds: Array<string>;
  type: "adjust_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResourcesBillingResponse3 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were removed.
   */
  resourceIds: Array<string>;
  type: "decrease_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResourcesBillingResponse2 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were added.
   */
  resourceIds: Array<string>;
  type: "increase_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResourcesBillingResponse1 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  type: "set_plan_item_quantity";
  /**
   * The full set of resource IDs after the set operation.
   */
  resourceIds?: Array<string> | undefined;
};

export type BuyCreditsConfigurationBillingChangedResources =
  | BuyCreditsChangedResourcesBillingResponse1
  | BuyCreditsChangedResourcesBillingResponse2
  | BuyCreditsChangedResourcesBillingResponse3
  | BuyCreditsChangedResourcesBillingResponse4;

/**
 * Output returned after configuring an OrbSubscriptionIntent.
 */
export type BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOutput =
  {
    /**
     * The Orb price ID for the subscription item being modified.
     */
    orbPriceId: string;
    /**
     * The product ID associated with this intent.
     */
    productId: string;
    /**
     * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
     */
    changedResources?:
      | Array<
        | BuyCreditsChangedResourcesBillingResponse1
        | BuyCreditsChangedResourcesBillingResponse2
        | BuyCreditsChangedResourcesBillingResponse3
        | BuyCreditsChangedResourcesBillingResponse4
      >
      | undefined;
    /**
     * Optional metadata associated with the intent to update the Orb subscription with.
     */
    metadata?: { [k: string]: string } | undefined;
    /**
     * The ID of the pending subscription change if there is one.
     */
    pendingSubscriptionChangeId?: string | undefined;
  };

/**
 * Configuration for the Orb subscription intent.
 */
export type Configuration4 = {
  /**
   * Configuration input options for adjusting plan item quantity.
   */
  options:
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3OrbSubscriptionIntentOptions;
  /**
   * Output returned after configuring an OrbSubscriptionIntent.
   */
  output:
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOutput;
  type: "adjust_plan_item_quantity";
};

/**
 * Configuration input options for decreasing plan item quantity.
 */
export type BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3Options =
  {
    /**
     * The alias of the product to decrease quantity for.
     */
    productAlias: string;
    /**
     * The resource IDs to decrementally remove. The quantity of the plan item will be decreased by the number of resource IDs.
     */
    resourceIds: Array<string>;
  };

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResourcesBilling4 = {
  /**
   * Resource IDs that were added.
   */
  addedResourceIds: Array<string>;
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were removed.
   */
  removedResourceIds: Array<string>;
  type: "adjust_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResourcesBilling3 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were removed.
   */
  resourceIds: Array<string>;
  type: "decrease_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResourcesBilling2 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were added.
   */
  resourceIds: Array<string>;
  type: "increase_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResourcesBilling1 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  type: "set_plan_item_quantity";
  /**
   * The full set of resource IDs after the set operation.
   */
  resourceIds?: Array<string> | undefined;
};

export type BuyCreditsConfigurationChangedResources =
  | BuyCreditsChangedResourcesBilling1
  | BuyCreditsChangedResourcesBilling2
  | BuyCreditsChangedResourcesBilling3
  | BuyCreditsChangedResourcesBilling4;

/**
 * Output returned after configuring an OrbSubscriptionIntent.
 */
export type BuyCreditsConfigurationBillingResponse200ApplicationJSONOutput = {
  /**
   * The Orb price ID for the subscription item being modified.
   */
  orbPriceId: string;
  /**
   * The product ID associated with this intent.
   */
  productId: string;
  /**
   * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
   */
  changedResources?:
    | Array<
      | BuyCreditsChangedResourcesBilling1
      | BuyCreditsChangedResourcesBilling2
      | BuyCreditsChangedResourcesBilling3
      | BuyCreditsChangedResourcesBilling4
    >
    | undefined;
  /**
   * Optional metadata associated with the intent to update the Orb subscription with.
   */
  metadata?: { [k: string]: string } | undefined;
  /**
   * The ID of the pending subscription change if there is one.
   */
  pendingSubscriptionChangeId?: string | undefined;
};

/**
 * Configuration for the Orb subscription intent.
 */
export type Configuration3 = {
  /**
   * Configuration input options for decreasing plan item quantity.
   */
  options:
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3Options;
  /**
   * Output returned after configuring an OrbSubscriptionIntent.
   */
  output: BuyCreditsConfigurationBillingResponse200ApplicationJSONOutput;
  type: "decrease_plan_item_quantity";
};

/**
 * Configuration input options for increasing plan item quantity.
 */
export type BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOptions =
  {
    /**
     * The alias of the product to increase quantity for.
     */
    productAlias: string;
    /**
     * The resource IDs to incrementally add. The quantity of the plan item will be increased by the number of resource IDs.
     */
    resourceIds: Array<string>;
  };

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResources4 = {
  /**
   * Resource IDs that were added.
   */
  addedResourceIds: Array<string>;
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were removed.
   */
  removedResourceIds: Array<string>;
  type: "adjust_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResources3 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were removed.
   */
  resourceIds: Array<string>;
  type: "decrease_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResources2 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were added.
   */
  resourceIds: Array<string>;
  type: "increase_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type BuyCreditsChangedResources1 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  type: "set_plan_item_quantity";
  /**
   * The full set of resource IDs after the set operation.
   */
  resourceIds?: Array<string> | undefined;
};

export type ConfigurationChangedResources =
  | BuyCreditsChangedResources1
  | BuyCreditsChangedResources2
  | BuyCreditsChangedResources3
  | BuyCreditsChangedResources4;

/**
 * Output returned after configuring an OrbSubscriptionIntent.
 */
export type BuyCreditsConfigurationBillingResponse200Output = {
  /**
   * The Orb price ID for the subscription item being modified.
   */
  orbPriceId: string;
  /**
   * The product ID associated with this intent.
   */
  productId: string;
  /**
   * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
   */
  changedResources?:
    | Array<
      | BuyCreditsChangedResources1
      | BuyCreditsChangedResources2
      | BuyCreditsChangedResources3
      | BuyCreditsChangedResources4
    >
    | undefined;
  /**
   * Optional metadata associated with the intent to update the Orb subscription with.
   */
  metadata?: { [k: string]: string } | undefined;
  /**
   * The ID of the pending subscription change if there is one.
   */
  pendingSubscriptionChangeId?: string | undefined;
};

/**
 * Configuration for the Orb subscription intent.
 */
export type BuyCreditsConfiguration2 = {
  /**
   * Configuration input options for increasing plan item quantity.
   */
  options:
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOptions;
  /**
   * Output returned after configuring an OrbSubscriptionIntent.
   */
  output: BuyCreditsConfigurationBillingResponse200Output;
  type: "increase_plan_item_quantity";
};

/**
 * Configuration input options for setting plan item quantity.
 */
export type BuyCreditsConfigurationBillingResponse200ApplicationJSONOptions = {
  /**
   * The alias of the product to set quantity for.
   */
  productAlias: string;
  /**
   * The quantity to set for the plan item.
   */
  quantity: number;
  /**
   * The resource IDs for the plan item. Only set if SKU requires resource entitlements.
   */
  resourceIds?: Array<string> | undefined;
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type ChangedResources4 = {
  /**
   * Resource IDs that were added.
   */
  addedResourceIds: Array<string>;
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were removed.
   */
  removedResourceIds: Array<string>;
  type: "adjust_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type ChangedResources3 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were removed.
   */
  resourceIds: Array<string>;
  type: "decrease_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type ChangedResources2 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  /**
   * Resource IDs that were added.
   */
  resourceIds: Array<string>;
  type: "increase_plan_item_quantity";
};

/**
 * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
 */
export type ChangedResources1 = {
  /**
   * The alias of the product that was changed.
   */
  productAlias: string;
  /**
   * The ID of the product that was changed.
   */
  productId: string;
  /**
   * The resulting quantity after this change.
   */
  quantity: number;
  type: "set_plan_item_quantity";
  /**
   * The full set of resource IDs after the set operation.
   */
  resourceIds?: Array<string> | undefined;
};

export type ChangedResources =
  | ChangedResources1
  | ChangedResources2
  | ChangedResources3
  | ChangedResources4;

/**
 * Output returned after configuring an OrbSubscriptionIntent.
 */
export type BuyCreditsConfigurationBillingResponseOutput = {
  /**
   * The Orb price ID for the subscription item being modified.
   */
  orbPriceId: string;
  /**
   * The product ID associated with this intent.
   */
  productId: string;
  /**
   * Resources that were changed as part of this intent. Tracks all logical changes including the primary change and any side effects.
   */
  changedResources?:
    | Array<
      | ChangedResources1
      | ChangedResources2
      | ChangedResources3
      | ChangedResources4
    >
    | undefined;
  /**
   * Optional metadata associated with the intent to update the Orb subscription with.
   */
  metadata?: { [k: string]: string } | undefined;
  /**
   * The ID of the pending subscription change if there is one.
   */
  pendingSubscriptionChangeId?: string | undefined;
};

/**
 * Configuration for the Orb subscription intent.
 */
export type BuyCreditsConfiguration1 = {
  /**
   * Configuration input options for setting plan item quantity.
   */
  options: BuyCreditsConfigurationBillingResponse200ApplicationJSONOptions;
  /**
   * Output returned after configuring an OrbSubscriptionIntent.
   */
  output: BuyCreditsConfigurationBillingResponseOutput;
  type: "set_plan_item_quantity";
};

export type ResponseBodyConfiguration =
  | BuyCreditsConfiguration1
  | BuyCreditsConfiguration2
  | Configuration3
  | Configuration4;

/**
 * The status of the Orb subscription intent.
 */
export const BuyCreditsResponseBodyStatus = {
  Failed: "failed",
  Pending: "pending",
  Succeeded: "succeeded",
} as const;
/**
 * The status of the Orb subscription intent.
 */
export type BuyCreditsResponseBodyStatus = ClosedEnum<
  typeof BuyCreditsResponseBodyStatus
>;

export type OrbSubscriptionIntent = {
  /**
   * The ID of the Orb subscription intent with the format `orbsubint_`.
   */
  id: string;
  configuration:
    | BuyCreditsConfiguration1
    | BuyCreditsConfiguration2
    | Configuration3
    | Configuration4;
  /**
   * The ISO 8601 date-time that the intent was created.
   */
  createdAt: string;
  /**
   * The Orb subscription ID this intent is associated with.
   */
  orbSubscriptionId: string;
  /**
   * The owner ID for this intent (e.g., team or user ID).
   */
  ownerId: string;
  /**
   * The status of the Orb subscription intent.
   */
  status: BuyCreditsResponseBodyStatus;
  /**
   * The ISO 8601 date-time that the intent was last updated.
   */
  updatedAt: string;
  /**
   * Optional purchase intent ID if this is associated with a purchase.
   */
  purchaseIntentId?: string | undefined;
};

export type BuyCreditsResponseBody3 = {
  orbSubscriptionIntent: OrbSubscriptionIntent;
};

/**
 * The line items that make up the Purchase Intent.
 */
export type ConfigurationLineItems = {
  /**
   * The ID of the line item
   */
  id: string;
  /**
   * The description of the line item
   */
  description: string;
  /**
   * The name of the line item
   */
  name: string;
  /**
   * The ID of the product being purchased
   */
  productId: string;
  /**
   * The quantity of the line item
   */
  quantity: string;
  /**
   * The unit amount of the line item
   */
  unitAmount: string;
  /**
   * Optional metadata for the line item
   */
  metadata?: { [k: string]: string } | undefined;
  /**
   * The alias of the product being purchased
   */
  productAlias?: string | undefined;
  /**
   * The amount of the line item that has been refunded
   */
  refund?: string | undefined;
};

export type BuyCreditsConfigurationBillingResponse200Options = {
  /**
   * The ID of the Orb customer to create
   */
  orbCustomerId: string;
  /**
   * The external ID of the Orb customer to create
   */
  orbExternalCustomerId: string;
  /**
   * The external ID of the Orb plan to create
   */
  orbExternalPlanId: string;
  /**
   * The ID of the pending subscription change
   */
  orbPendingSubscriptionChangeId: string;
  /**
   * The ID of the Orb plan to create
   */
  orbPlanId: string;
  /**
   * The ID of the Orb subscription to create
   */
  orbSubscriptionId: string;
  /**
   * The line items that make up the Purchase Intent.
   */
  lineItems?: Array<ConfigurationLineItems> | undefined;
};

export type BuyCreditsConfigurationBillingOutput = {
  /**
   * The ID of the pending subscription change
   */
  pendingSubscriptionChangeId: string;
};

/**
 * The configuration for a credit purchase
 */
export type Configuration6 = {
  options: BuyCreditsConfigurationBillingResponse200Options;
  output: BuyCreditsConfigurationBillingOutput;
  type: "orb_subscription_intent";
};

/**
 * The prices to add to the subscription
 */
export type AddPrices2 = {};

/**
 * The prices to add to the subscription
 */
export type AddPrices1 = {
  /**
   * The ID of the price to add
   */
  priceId: string;
};

export type AddPrices = AddPrices1 | AddPrices2;

/**
 * The prices to remove in the subscription
 */
export type RemovePrices = {
  /**
   * The ID of the price to remove
   */
  priceId: string;
};

/**
 * The prices to replace in the subscription
 */
export type ConfigurationReplacePrices = {
  /**
   * The quantity for the fixed price
   */
  fixedPriceQuantity: number;
  /**
   * The ID of the price to replace
   */
  replacesPriceId: string;
};

export type BuyCreditsConfigurationBillingResponseOptions = {
  /**
   * The external plan ID of the Orb plan to subscribe to
   */
  externalPlanId: string;
  /**
   * The prices to add to the subscription
   */
  addPrices?: Array<AddPrices1 | AddPrices2> | undefined;
  /**
   * Whether to align the subscription start date with the billing subscription start date
   */
  alignBillingWithSubscriptionStartDate?: boolean | undefined;
  /**
   * The coupon redemption code to apply to the subscription
   */
  couponRedemptionCode?: string | undefined;
  /**
   * The initial phase order to use for the subscription
   */
  initialPhaseOrder?: number | undefined;
  /**
   * Optional metadata to associate with the subscription
   */
  metadata?: { [k: string]: string | null } | undefined;
  /**
   * The prices to remove in the subscription
   */
  removePrices?: Array<RemovePrices> | undefined;
  /**
   * The prices to replace in the subscription
   */
  replacePrices?: Array<ConfigurationReplacePrices> | undefined;
  /**
   * The start date of the subscription
   */
  startDate?: string | undefined;
};

export type BuyCreditsConfigurationOutput = {
  /**
   * The ID of the pending subscription change
   */
  pendingSubscriptionChangeId: string;
};

/**
 * The configuration for a credit purchase
 */
export type Configuration5 = {
  options: BuyCreditsConfigurationBillingResponseOptions;
  output: BuyCreditsConfigurationOutput;
  type: "orb_subscription";
};

export type BuyCreditsConfigurationBillingOptions = {};

export type ConfigurationOutput = {
  /**
   * The ID of the pending subscription change
   */
  pendingSubscriptionChangeId: string;
};

/**
 * The configuration for a credit purchase
 */
export type BuyCreditsConfiguration4 = {
  options: BuyCreditsConfigurationBillingOptions;
  output: ConfigurationOutput;
  type: "orb_price_interval";
};

export const EffectiveDate2 = {
  EndOfSubscriptionTerm: "end_of_subscription_term",
  Immediate: "immediate",
} as const;
export type EffectiveDate2 = ClosedEnum<typeof EffectiveDate2>;

/**
 * The effective date of the plan change
 */
export type EffectiveDate1 = {};

export type EffectiveDate = EffectiveDate1 | EffectiveDate2;

/**
 * The prices to replace in the subscription
 */
export type ReplacePrices = {
  /**
   * The quantity for the fixed price
   */
  fixedPriceQuantity: number;
  /**
   * The ID of the price to replace
   */
  replacesPriceId: string;
};

export type BuyCreditsConfigurationOptions = {
  effectiveDate: EffectiveDate1 | EffectiveDate2;
  /**
   * The ID of the Orb subscription to change
   */
  orbSubscriptionId: string;
  /**
   * Whether or not to reset the billing cycle
   */
  alignBillingWithPlanChangeDate?: boolean | undefined;
  /**
   * The coupon redemption code to apply to the plan change
   */
  couponRedemptionCode?: string | undefined;
  /**
   * The ID of the external plan to change to
   */
  externalPlanId?: string | undefined;
  /**
   * The prices to replace in the subscription
   */
  replacePrices?: Array<ReplacePrices> | undefined;
};

export type BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Output =
  {
    /**
     * The ID of the pending subscription change
     */
    pendingSubscriptionChangeId: string;
  };

/**
 * The configuration for a credit purchase
 */
export type BuyCreditsConfiguration3 = {
  options: BuyCreditsConfigurationOptions;
  output:
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Output;
  type: "orb_plan_change";
};

export const BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Type =
  {
    Purchase: "purchase",
    Renewal: "renewal",
    Transfer: "transfer",
  } as const;
export type BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Type =
  ClosedEnum<
    typeof BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Type
  >;

export type ConfigurationItems = {
  name: string;
  /**
   * The subtotal of the domain name purchase
   */
  subtotal: string;
  type:
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Type;
  /**
   * The number of years to purchase
   */
  years: number;
};

export type ConfigurationOptions = {
  items: Array<ConfigurationItems>;
  /**
   * The order ID of the domain name purchase
   */
  orderId: string;
};

/**
 * The configuration for a credit purchase
 */
export type Configuration2 = {
  options: ConfigurationOptions;
  output?: any | null | undefined;
  type: "domain_name";
};

/**
 * The currency being purchased
 */
export const ConfigurationCurrency = {
  AiCredits: "ai_credits",
  AiGatewayCredits: "ai_gateway_credits",
  CopperTestUnits: "copper_test_units",
  V0UserCredits: "v0_user_credits",
  VercelAgentCredits: "vercel_agent_credits",
} as const;
/**
 * The currency being purchased
 */
export type ConfigurationCurrency = ClosedEnum<typeof ConfigurationCurrency>;

/**
 * Purchase configuration specific options
 */
export type BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Options =
  {
    /**
     * The amount of currency to buy
     */
    amount: string;
    /**
     * The currency being purchased
     */
    currency: ConfigurationCurrency;
    /**
     * The expiration date of the credits being purchased
     */
    expirationDate?: string | undefined;
  };

/**
 * The configuration for a credit purchase
 */
export type Configuration1 = {
  /**
   * Purchase configuration specific options
   */
  options:
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Options;
  output?: any | null | undefined;
  type: "credit_topup";
};

export type BuyCreditsResponseBodyConfiguration =
  | Configuration1
  | Configuration2
  | BuyCreditsConfiguration3
  | BuyCreditsConfiguration4
  | Configuration5
  | Configuration6;

/**
 * The currency for the purchase intent
 */
export const Currency = {
  Miu: "miu",
  Usd: "usd",
} as const;
/**
 * The currency for the purchase intent
 */
export type Currency = ClosedEnum<typeof Currency>;

/**
 * The type of the purchase provider
 */
export const BuyCreditsResponseBodyType = {
  AppleInAppPurchase: "apple_in_app_purchase",
  OrbLedger: "orb_ledger",
  StripeElements: "stripe_elements",
  StripeHosted: "stripe_hosted",
  StripeInvoiceDeferred: "stripe_invoice_deferred",
  StripeInvoiceElements: "stripe_invoice_elements",
  StripeInvoiceImmediate: "stripe_invoice_immediate",
  TackleAwsMarketplace: "tackle_aws_marketplace",
} as const;
/**
 * The type of the purchase provider
 */
export type BuyCreditsResponseBodyType = ClosedEnum<
  typeof BuyCreditsResponseBodyType
>;

export type ResponseBodyProvider = {
  /**
   * Provider resource id
   */
  resourceId: string;
  /**
   * The type of the purchase provider
   */
  type: BuyCreditsResponseBodyType;
  /**
   * The currency conversion rate used by the provider
   */
  currencyConversionRate?: string | undefined;
  /**
   * Whether a Stripe Shared Payment Token was used for this purchase. Only applicable when type is stripe_invoice_immediate.
   */
  stripeSharedPaymentTokenUsed?: boolean | undefined;
};

/**
 * The status of the Purchase Intent.
 */
export const BuyCreditsResponseBodyBillingStatus = {
  Failed: "failed",
  Pending: "pending",
  Succeeded: "succeeded",
} as const;
/**
 * The status of the Purchase Intent.
 */
export type BuyCreditsResponseBodyBillingStatus = ClosedEnum<
  typeof BuyCreditsResponseBodyBillingStatus
>;

/**
 * The dispute details, if any.
 */
export type Dispute = {
  /**
   * The unique ID of the dispute entity.
   */
  id: string;
  /**
   * The disputed amount.
   */
  amount: string;
  /**
   * When the dispute was first recorded.
   */
  createdAt: string;
  /**
   * The dispute currency.
   */
  currency: string;
  /**
   * The external provider dispute ID (e.g. Stripe dispute ID).
   */
  providerId: string;
  /**
   * The dispute reason.
   */
  reason: string | null;
  /**
   * The dispute status.
   */
  status: string;
  /**
   * When the dispute was last updated.
   */
  updatedAt: string;
};

/**
 * The line items that make up the Purchase Intent.
 */
export type LineItems = {
  /**
   * The ID of the line item
   */
  id: string;
  /**
   * The description of the line item
   */
  description: string;
  /**
   * The name of the line item
   */
  name: string;
  /**
   * The ID of the product being purchased
   */
  productId: string;
  /**
   * The quantity of the line item
   */
  quantity: string;
  /**
   * The unit amount of the line item
   */
  unitAmount: string;
  /**
   * Optional metadata for the line item
   */
  metadata?: { [k: string]: string } | undefined;
  /**
   * The alias of the product being purchased
   */
  productAlias?: string | undefined;
  /**
   * The amount of the line item that has been refunded
   */
  refund?: string | undefined;
};

/**
 * The created purchase intent
 */
export type PurchaseIntent = {
  /**
   * The unique ID of a Purchase Intent. Uses the format `pur_*`
   */
  id: string;
  configuration:
    | Configuration1
    | Configuration2
    | BuyCreditsConfiguration3
    | BuyCreditsConfiguration4
    | Configuration5
    | Configuration6;
  /**
   * The datetime when the Purchase Intent was created.
   */
  createdAt: string;
  /**
   * The currency for the purchase intent
   */
  currency: Currency;
  /**
   * The ID of the owner of the Purchase Intent.
   */
  ownerId: string;
  provider: ResponseBodyProvider;
  /**
   * The status of the Purchase Intent.
   */
  status: BuyCreditsResponseBodyBillingStatus;
  /**
   * The subtotal of the Purchase Intent.
   */
  subtotal: string;
  /**
   * The tax due on the Purchase Intent.
   */
  tax: string;
  /**
   * The total balance due on the Purchase Intent.
   */
  total: string;
  /**
   * The datetime when the Purchase Intent was last updated.
   */
  updatedAt: string;
  /**
   * The dispute details, if any.
   */
  dispute?: Dispute | undefined;
  /**
   * The line items that make up the Purchase Intent.
   */
  lineItems?: Array<LineItems> | undefined;
  /**
   * Optional metadata associated with the purchase intent
   */
  metadata?: { [k: string]: string } | undefined;
  /**
   * The amount of the purchase intent that has been refunded
   */
  refund?: string | undefined;
  /**
   * The URL to redirect to after the purchase is complete
   */
  returnUrl?: string | undefined;
};

export type BuyCreditsResponseBody2 = {
  /**
   * The created purchase intent
   */
  purchaseIntent: PurchaseIntent;
};

export type BuyCreditsResponseBody1 = {
  checkoutSessionId: string;
  checkoutSessionUrl: string;
};

export type BuyCreditsResponseBody =
  | BuyCreditsResponseBody1
  | BuyCreditsResponseBody2
  | BuyCreditsResponseBody3;

/** @internal */
export const BuyCreditsType$outboundSchema: z.ZodNativeEnum<
  typeof BuyCreditsType
> = z.nativeEnum(BuyCreditsType);

/** @internal */
export const CreditType$outboundSchema: z.ZodNativeEnum<typeof CreditType> = z
  .nativeEnum(CreditType);

/** @internal */
export type Item$Outbound = {
  type: string;
  creditType: string;
  amount: number;
};

/** @internal */
export const Item$outboundSchema: z.ZodType<Item$Outbound, z.ZodTypeDef, Item> =
  z.object({
    type: BuyCreditsType$outboundSchema,
    creditType: CreditType$outboundSchema,
    amount: z.number().int(),
  });

export function itemToJSON(item: Item): string {
  return JSON.stringify(Item$outboundSchema.parse(item));
}

/** @internal */
export type BuyCreditsRequestBody$Outbound = {
  item: Item$Outbound;
};

/** @internal */
export const BuyCreditsRequestBody$outboundSchema: z.ZodType<
  BuyCreditsRequestBody$Outbound,
  z.ZodTypeDef,
  BuyCreditsRequestBody
> = z.object({
  item: z.lazy(() => Item$outboundSchema),
});

export function buyCreditsRequestBodyToJSON(
  buyCreditsRequestBody: BuyCreditsRequestBody,
): string {
  return JSON.stringify(
    BuyCreditsRequestBody$outboundSchema.parse(buyCreditsRequestBody),
  );
}

/** @internal */
export type BuyCreditsRequest$Outbound = {
  source?: string | undefined;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody: BuyCreditsRequestBody$Outbound;
};

/** @internal */
export const BuyCreditsRequest$outboundSchema: z.ZodType<
  BuyCreditsRequest$Outbound,
  z.ZodTypeDef,
  BuyCreditsRequest
> = z.object({
  source: z.string().optional(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
  requestBody: z.lazy(() => BuyCreditsRequestBody$outboundSchema),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

export function buyCreditsRequestToJSON(
  buyCreditsRequest: BuyCreditsRequest,
): string {
  return JSON.stringify(
    BuyCreditsRequest$outboundSchema.parse(buyCreditsRequest),
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3OrbSubscriptionIntentOptions$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3OrbSubscriptionIntentOptions,
    z.ZodTypeDef,
    unknown
  > = z.object({
    addedResourceIds: z.array(types.string()),
    productAlias: types.string(),
    removedResourceIds: z.array(types.string()),
  });

export function buyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3OrbSubscriptionIntentOptionsFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3OrbSubscriptionIntentOptions,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3OrbSubscriptionIntentOptions$inboundSchema
        .parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3OrbSubscriptionIntentOptions' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResourcesBillingResponse4$inboundSchema:
  z.ZodType<BuyCreditsChangedResourcesBillingResponse4, z.ZodTypeDef, unknown> =
    z.object({
      addedResourceIds: z.array(types.string()),
      productAlias: types.string(),
      productId: types.string(),
      quantity: types.number(),
      removedResourceIds: z.array(types.string()),
      type: types.literal("adjust_plan_item_quantity"),
    });

export function buyCreditsChangedResourcesBillingResponse4FromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsChangedResourcesBillingResponse4,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsChangedResourcesBillingResponse4$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'BuyCreditsChangedResourcesBillingResponse4' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResourcesBillingResponse3$inboundSchema:
  z.ZodType<BuyCreditsChangedResourcesBillingResponse3, z.ZodTypeDef, unknown> =
    z.object({
      productAlias: types.string(),
      productId: types.string(),
      quantity: types.number(),
      resourceIds: z.array(types.string()),
      type: types.literal("decrease_plan_item_quantity"),
    });

export function buyCreditsChangedResourcesBillingResponse3FromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsChangedResourcesBillingResponse3,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsChangedResourcesBillingResponse3$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'BuyCreditsChangedResourcesBillingResponse3' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResourcesBillingResponse2$inboundSchema:
  z.ZodType<BuyCreditsChangedResourcesBillingResponse2, z.ZodTypeDef, unknown> =
    z.object({
      productAlias: types.string(),
      productId: types.string(),
      quantity: types.number(),
      resourceIds: z.array(types.string()),
      type: types.literal("increase_plan_item_quantity"),
    });

export function buyCreditsChangedResourcesBillingResponse2FromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsChangedResourcesBillingResponse2,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsChangedResourcesBillingResponse2$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'BuyCreditsChangedResourcesBillingResponse2' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResourcesBillingResponse1$inboundSchema:
  z.ZodType<BuyCreditsChangedResourcesBillingResponse1, z.ZodTypeDef, unknown> =
    z.object({
      productAlias: types.string(),
      productId: types.string(),
      quantity: types.number(),
      type: types.literal("set_plan_item_quantity"),
      resourceIds: types.optional(z.array(types.string())),
    });

export function buyCreditsChangedResourcesBillingResponse1FromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsChangedResourcesBillingResponse1,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsChangedResourcesBillingResponse1$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'BuyCreditsChangedResourcesBillingResponse1' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingChangedResources$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingChangedResources,
    z.ZodTypeDef,
    unknown
  > = z.union([
    z.lazy(() => BuyCreditsChangedResourcesBillingResponse1$inboundSchema),
    z.lazy(() => BuyCreditsChangedResourcesBillingResponse2$inboundSchema),
    z.lazy(() => BuyCreditsChangedResourcesBillingResponse3$inboundSchema),
    z.lazy(() => BuyCreditsChangedResourcesBillingResponse4$inboundSchema),
  ]);

export function buyCreditsConfigurationBillingChangedResourcesFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingChangedResources,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingChangedResources$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'BuyCreditsConfigurationBillingChangedResources' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOutput$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOutput,
    z.ZodTypeDef,
    unknown
  > = z.object({
    orbPriceId: types.string(),
    productId: types.string(),
    changedResources: types.optional(
      z.array(z.union([
        z.lazy(() => BuyCreditsChangedResourcesBillingResponse1$inboundSchema),
        z.lazy(() =>
          BuyCreditsChangedResourcesBillingResponse2$inboundSchema
        ),
        z.lazy(() => BuyCreditsChangedResourcesBillingResponse3$inboundSchema),
        z.lazy(() => BuyCreditsChangedResourcesBillingResponse4$inboundSchema),
      ])),
    ),
    metadata: types.optional(z.record(types.string())),
    pendingSubscriptionChangeId: types.optional(types.string()),
  });

export function buyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOutputFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOutput,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOutput$inboundSchema
        .parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOutput' from JSON`,
  );
}

/** @internal */
export const Configuration4$inboundSchema: z.ZodType<
  Configuration4,
  z.ZodTypeDef,
  unknown
> = z.object({
  options: z.lazy(() =>
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3OrbSubscriptionIntentOptions$inboundSchema
  ),
  output: z.lazy(() =>
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOutput$inboundSchema
  ),
  type: types.literal("adjust_plan_item_quantity"),
});

export function configuration4FromJSON(
  jsonString: string,
): SafeParseResult<Configuration4, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Configuration4$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Configuration4' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3Options$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3Options,
    z.ZodTypeDef,
    unknown
  > = z.object({
    productAlias: types.string(),
    resourceIds: z.array(types.string()),
  });

export function buyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3OptionsFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3Options,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3Options$inboundSchema
        .parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3Options' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResourcesBilling4$inboundSchema: z.ZodType<
  BuyCreditsChangedResourcesBilling4,
  z.ZodTypeDef,
  unknown
> = z.object({
  addedResourceIds: z.array(types.string()),
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  removedResourceIds: z.array(types.string()),
  type: types.literal("adjust_plan_item_quantity"),
});

export function buyCreditsChangedResourcesBilling4FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsChangedResourcesBilling4, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsChangedResourcesBilling4$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsChangedResourcesBilling4' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResourcesBilling3$inboundSchema: z.ZodType<
  BuyCreditsChangedResourcesBilling3,
  z.ZodTypeDef,
  unknown
> = z.object({
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  resourceIds: z.array(types.string()),
  type: types.literal("decrease_plan_item_quantity"),
});

export function buyCreditsChangedResourcesBilling3FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsChangedResourcesBilling3, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsChangedResourcesBilling3$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsChangedResourcesBilling3' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResourcesBilling2$inboundSchema: z.ZodType<
  BuyCreditsChangedResourcesBilling2,
  z.ZodTypeDef,
  unknown
> = z.object({
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  resourceIds: z.array(types.string()),
  type: types.literal("increase_plan_item_quantity"),
});

export function buyCreditsChangedResourcesBilling2FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsChangedResourcesBilling2, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsChangedResourcesBilling2$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsChangedResourcesBilling2' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResourcesBilling1$inboundSchema: z.ZodType<
  BuyCreditsChangedResourcesBilling1,
  z.ZodTypeDef,
  unknown
> = z.object({
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  type: types.literal("set_plan_item_quantity"),
  resourceIds: types.optional(z.array(types.string())),
});

export function buyCreditsChangedResourcesBilling1FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsChangedResourcesBilling1, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsChangedResourcesBilling1$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsChangedResourcesBilling1' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationChangedResources$inboundSchema: z.ZodType<
  BuyCreditsConfigurationChangedResources,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => BuyCreditsChangedResourcesBilling1$inboundSchema),
  z.lazy(() => BuyCreditsChangedResourcesBilling2$inboundSchema),
  z.lazy(() => BuyCreditsChangedResourcesBilling3$inboundSchema),
  z.lazy(() => BuyCreditsChangedResourcesBilling4$inboundSchema),
]);

export function buyCreditsConfigurationChangedResourcesFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationChangedResources,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationChangedResources$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'BuyCreditsConfigurationChangedResources' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponse200ApplicationJSONOutput$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponse200ApplicationJSONOutput,
    z.ZodTypeDef,
    unknown
  > = z.object({
    orbPriceId: types.string(),
    productId: types.string(),
    changedResources: types.optional(
      z.array(z.union([
        z.lazy(() => BuyCreditsChangedResourcesBilling1$inboundSchema),
        z.lazy(() =>
          BuyCreditsChangedResourcesBilling2$inboundSchema
        ),
        z.lazy(() => BuyCreditsChangedResourcesBilling3$inboundSchema),
        z.lazy(() => BuyCreditsChangedResourcesBilling4$inboundSchema),
      ])),
    ),
    metadata: types.optional(z.record(types.string())),
    pendingSubscriptionChangeId: types.optional(types.string()),
  });

export function buyCreditsConfigurationBillingResponse200ApplicationJSONOutputFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponse200ApplicationJSONOutput,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponse200ApplicationJSONOutput$inboundSchema
        .parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationBillingResponse200ApplicationJSONOutput' from JSON`,
  );
}

/** @internal */
export const Configuration3$inboundSchema: z.ZodType<
  Configuration3,
  z.ZodTypeDef,
  unknown
> = z.object({
  options: z.lazy(() =>
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody3Options$inboundSchema
  ),
  output: z.lazy(() =>
    BuyCreditsConfigurationBillingResponse200ApplicationJSONOutput$inboundSchema
  ),
  type: types.literal("decrease_plan_item_quantity"),
});

export function configuration3FromJSON(
  jsonString: string,
): SafeParseResult<Configuration3, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Configuration3$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Configuration3' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOptions$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOptions,
    z.ZodTypeDef,
    unknown
  > = z.object({
    productAlias: types.string(),
    resourceIds: z.array(types.string()),
  });

export function buyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOptionsFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOptions,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOptions$inboundSchema
        .parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOptions' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResources4$inboundSchema: z.ZodType<
  BuyCreditsChangedResources4,
  z.ZodTypeDef,
  unknown
> = z.object({
  addedResourceIds: z.array(types.string()),
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  removedResourceIds: z.array(types.string()),
  type: types.literal("adjust_plan_item_quantity"),
});

export function buyCreditsChangedResources4FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsChangedResources4, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsChangedResources4$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsChangedResources4' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResources3$inboundSchema: z.ZodType<
  BuyCreditsChangedResources3,
  z.ZodTypeDef,
  unknown
> = z.object({
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  resourceIds: z.array(types.string()),
  type: types.literal("decrease_plan_item_quantity"),
});

export function buyCreditsChangedResources3FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsChangedResources3, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsChangedResources3$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsChangedResources3' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResources2$inboundSchema: z.ZodType<
  BuyCreditsChangedResources2,
  z.ZodTypeDef,
  unknown
> = z.object({
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  resourceIds: z.array(types.string()),
  type: types.literal("increase_plan_item_quantity"),
});

export function buyCreditsChangedResources2FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsChangedResources2, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsChangedResources2$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsChangedResources2' from JSON`,
  );
}

/** @internal */
export const BuyCreditsChangedResources1$inboundSchema: z.ZodType<
  BuyCreditsChangedResources1,
  z.ZodTypeDef,
  unknown
> = z.object({
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  type: types.literal("set_plan_item_quantity"),
  resourceIds: types.optional(z.array(types.string())),
});

export function buyCreditsChangedResources1FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsChangedResources1, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsChangedResources1$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsChangedResources1' from JSON`,
  );
}

/** @internal */
export const ConfigurationChangedResources$inboundSchema: z.ZodType<
  ConfigurationChangedResources,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => BuyCreditsChangedResources1$inboundSchema),
  z.lazy(() => BuyCreditsChangedResources2$inboundSchema),
  z.lazy(() => BuyCreditsChangedResources3$inboundSchema),
  z.lazy(() => BuyCreditsChangedResources4$inboundSchema),
]);

export function configurationChangedResourcesFromJSON(
  jsonString: string,
): SafeParseResult<ConfigurationChangedResources, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ConfigurationChangedResources$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ConfigurationChangedResources' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponse200Output$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponse200Output,
    z.ZodTypeDef,
    unknown
  > = z.object({
    orbPriceId: types.string(),
    productId: types.string(),
    changedResources: types.optional(
      z.array(z.union([
        z.lazy(() => BuyCreditsChangedResources1$inboundSchema),
        z.lazy(() =>
          BuyCreditsChangedResources2$inboundSchema
        ),
        z.lazy(() => BuyCreditsChangedResources3$inboundSchema),
        z.lazy(() => BuyCreditsChangedResources4$inboundSchema),
      ])),
    ),
    metadata: types.optional(z.record(types.string())),
    pendingSubscriptionChangeId: types.optional(types.string()),
  });

export function buyCreditsConfigurationBillingResponse200OutputFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponse200Output,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponse200Output$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'BuyCreditsConfigurationBillingResponse200Output' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfiguration2$inboundSchema: z.ZodType<
  BuyCreditsConfiguration2,
  z.ZodTypeDef,
  unknown
> = z.object({
  options: z.lazy(() =>
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBodyOptions$inboundSchema
  ),
  output: z.lazy(() =>
    BuyCreditsConfigurationBillingResponse200Output$inboundSchema
  ),
  type: types.literal("increase_plan_item_quantity"),
});

export function buyCreditsConfiguration2FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsConfiguration2, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsConfiguration2$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfiguration2' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponse200ApplicationJSONOptions$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponse200ApplicationJSONOptions,
    z.ZodTypeDef,
    unknown
  > = z.object({
    productAlias: types.string(),
    quantity: types.number(),
    resourceIds: types.optional(z.array(types.string())),
  });

export function buyCreditsConfigurationBillingResponse200ApplicationJSONOptionsFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponse200ApplicationJSONOptions,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponse200ApplicationJSONOptions$inboundSchema
        .parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationBillingResponse200ApplicationJSONOptions' from JSON`,
  );
}

/** @internal */
export const ChangedResources4$inboundSchema: z.ZodType<
  ChangedResources4,
  z.ZodTypeDef,
  unknown
> = z.object({
  addedResourceIds: z.array(types.string()),
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  removedResourceIds: z.array(types.string()),
  type: types.literal("adjust_plan_item_quantity"),
});

export function changedResources4FromJSON(
  jsonString: string,
): SafeParseResult<ChangedResources4, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ChangedResources4$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ChangedResources4' from JSON`,
  );
}

/** @internal */
export const ChangedResources3$inboundSchema: z.ZodType<
  ChangedResources3,
  z.ZodTypeDef,
  unknown
> = z.object({
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  resourceIds: z.array(types.string()),
  type: types.literal("decrease_plan_item_quantity"),
});

export function changedResources3FromJSON(
  jsonString: string,
): SafeParseResult<ChangedResources3, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ChangedResources3$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ChangedResources3' from JSON`,
  );
}

/** @internal */
export const ChangedResources2$inboundSchema: z.ZodType<
  ChangedResources2,
  z.ZodTypeDef,
  unknown
> = z.object({
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  resourceIds: z.array(types.string()),
  type: types.literal("increase_plan_item_quantity"),
});

export function changedResources2FromJSON(
  jsonString: string,
): SafeParseResult<ChangedResources2, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ChangedResources2$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ChangedResources2' from JSON`,
  );
}

/** @internal */
export const ChangedResources1$inboundSchema: z.ZodType<
  ChangedResources1,
  z.ZodTypeDef,
  unknown
> = z.object({
  productAlias: types.string(),
  productId: types.string(),
  quantity: types.number(),
  type: types.literal("set_plan_item_quantity"),
  resourceIds: types.optional(z.array(types.string())),
});

export function changedResources1FromJSON(
  jsonString: string,
): SafeParseResult<ChangedResources1, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ChangedResources1$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ChangedResources1' from JSON`,
  );
}

/** @internal */
export const ChangedResources$inboundSchema: z.ZodType<
  ChangedResources,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => ChangedResources1$inboundSchema),
  z.lazy(() => ChangedResources2$inboundSchema),
  z.lazy(() => ChangedResources3$inboundSchema),
  z.lazy(() => ChangedResources4$inboundSchema),
]);

export function changedResourcesFromJSON(
  jsonString: string,
): SafeParseResult<ChangedResources, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ChangedResources$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ChangedResources' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponseOutput$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponseOutput,
    z.ZodTypeDef,
    unknown
  > = z.object({
    orbPriceId: types.string(),
    productId: types.string(),
    changedResources: types.optional(
      z.array(z.union([
        z.lazy(() => ChangedResources1$inboundSchema),
        z.lazy(() =>
          ChangedResources2$inboundSchema
        ),
        z.lazy(() => ChangedResources3$inboundSchema),
        z.lazy(() => ChangedResources4$inboundSchema),
      ])),
    ),
    metadata: types.optional(z.record(types.string())),
    pendingSubscriptionChangeId: types.optional(types.string()),
  });

export function buyCreditsConfigurationBillingResponseOutputFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponseOutput,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponseOutput$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'BuyCreditsConfigurationBillingResponseOutput' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfiguration1$inboundSchema: z.ZodType<
  BuyCreditsConfiguration1,
  z.ZodTypeDef,
  unknown
> = z.object({
  options: z.lazy(() =>
    BuyCreditsConfigurationBillingResponse200ApplicationJSONOptions$inboundSchema
  ),
  output: z.lazy(() =>
    BuyCreditsConfigurationBillingResponseOutput$inboundSchema
  ),
  type: types.literal("set_plan_item_quantity"),
});

export function buyCreditsConfiguration1FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsConfiguration1, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsConfiguration1$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfiguration1' from JSON`,
  );
}

/** @internal */
export const ResponseBodyConfiguration$inboundSchema: z.ZodType<
  ResponseBodyConfiguration,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => BuyCreditsConfiguration1$inboundSchema),
  z.lazy(() => BuyCreditsConfiguration2$inboundSchema),
  z.lazy(() => Configuration3$inboundSchema),
  z.lazy(() => Configuration4$inboundSchema),
]);

export function responseBodyConfigurationFromJSON(
  jsonString: string,
): SafeParseResult<ResponseBodyConfiguration, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ResponseBodyConfiguration$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ResponseBodyConfiguration' from JSON`,
  );
}

/** @internal */
export const BuyCreditsResponseBodyStatus$inboundSchema: z.ZodNativeEnum<
  typeof BuyCreditsResponseBodyStatus
> = z.nativeEnum(BuyCreditsResponseBodyStatus);

/** @internal */
export const OrbSubscriptionIntent$inboundSchema: z.ZodType<
  OrbSubscriptionIntent,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  configuration: z.union([
    z.lazy(() => BuyCreditsConfiguration1$inboundSchema),
    z.lazy(() => BuyCreditsConfiguration2$inboundSchema),
    z.lazy(() => Configuration3$inboundSchema),
    z.lazy(() => Configuration4$inboundSchema),
  ]),
  createdAt: types.string(),
  orbSubscriptionId: types.string(),
  ownerId: types.string(),
  status: BuyCreditsResponseBodyStatus$inboundSchema,
  updatedAt: types.string(),
  purchaseIntentId: types.optional(types.string()),
});

export function orbSubscriptionIntentFromJSON(
  jsonString: string,
): SafeParseResult<OrbSubscriptionIntent, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => OrbSubscriptionIntent$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'OrbSubscriptionIntent' from JSON`,
  );
}

/** @internal */
export const BuyCreditsResponseBody3$inboundSchema: z.ZodType<
  BuyCreditsResponseBody3,
  z.ZodTypeDef,
  unknown
> = z.object({
  orbSubscriptionIntent: z.lazy(() => OrbSubscriptionIntent$inboundSchema),
});

export function buyCreditsResponseBody3FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsResponseBody3, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsResponseBody3$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsResponseBody3' from JSON`,
  );
}

/** @internal */
export const ConfigurationLineItems$inboundSchema: z.ZodType<
  ConfigurationLineItems,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  description: types.string(),
  name: types.string(),
  productId: types.string(),
  quantity: types.string(),
  unitAmount: types.string(),
  metadata: types.optional(z.record(types.string())),
  productAlias: types.optional(types.string()),
  refund: types.optional(types.string()),
});

export function configurationLineItemsFromJSON(
  jsonString: string,
): SafeParseResult<ConfigurationLineItems, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ConfigurationLineItems$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ConfigurationLineItems' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponse200Options$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponse200Options,
    z.ZodTypeDef,
    unknown
  > = z.object({
    orbCustomerId: types.string(),
    orbExternalCustomerId: types.string(),
    orbExternalPlanId: types.string(),
    orbPendingSubscriptionChangeId: types.string(),
    orbPlanId: types.string(),
    orbSubscriptionId: types.string(),
    lineItems: types.optional(
      z.array(z.lazy(() => ConfigurationLineItems$inboundSchema)),
    ),
  });

export function buyCreditsConfigurationBillingResponse200OptionsFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponse200Options,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponse200Options$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'BuyCreditsConfigurationBillingResponse200Options' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingOutput$inboundSchema: z.ZodType<
  BuyCreditsConfigurationBillingOutput,
  z.ZodTypeDef,
  unknown
> = z.object({
  pendingSubscriptionChangeId: types.string(),
});

export function buyCreditsConfigurationBillingOutputFromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsConfigurationBillingOutput, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingOutput$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationBillingOutput' from JSON`,
  );
}

/** @internal */
export const Configuration6$inboundSchema: z.ZodType<
  Configuration6,
  z.ZodTypeDef,
  unknown
> = z.object({
  options: z.lazy(() =>
    BuyCreditsConfigurationBillingResponse200Options$inboundSchema
  ),
  output: z.lazy(() => BuyCreditsConfigurationBillingOutput$inboundSchema),
  type: types.literal("orb_subscription_intent"),
});

export function configuration6FromJSON(
  jsonString: string,
): SafeParseResult<Configuration6, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Configuration6$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Configuration6' from JSON`,
  );
}

/** @internal */
export const AddPrices2$inboundSchema: z.ZodType<
  AddPrices2,
  z.ZodTypeDef,
  unknown
> = z.object({});

export function addPrices2FromJSON(
  jsonString: string,
): SafeParseResult<AddPrices2, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AddPrices2$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AddPrices2' from JSON`,
  );
}

/** @internal */
export const AddPrices1$inboundSchema: z.ZodType<
  AddPrices1,
  z.ZodTypeDef,
  unknown
> = z.object({
  priceId: types.string(),
});

export function addPrices1FromJSON(
  jsonString: string,
): SafeParseResult<AddPrices1, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AddPrices1$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AddPrices1' from JSON`,
  );
}

/** @internal */
export const AddPrices$inboundSchema: z.ZodType<
  AddPrices,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => AddPrices1$inboundSchema),
  z.lazy(() => AddPrices2$inboundSchema),
]);

export function addPricesFromJSON(
  jsonString: string,
): SafeParseResult<AddPrices, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AddPrices$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AddPrices' from JSON`,
  );
}

/** @internal */
export const RemovePrices$inboundSchema: z.ZodType<
  RemovePrices,
  z.ZodTypeDef,
  unknown
> = z.object({
  priceId: types.string(),
});

export function removePricesFromJSON(
  jsonString: string,
): SafeParseResult<RemovePrices, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => RemovePrices$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'RemovePrices' from JSON`,
  );
}

/** @internal */
export const ConfigurationReplacePrices$inboundSchema: z.ZodType<
  ConfigurationReplacePrices,
  z.ZodTypeDef,
  unknown
> = z.object({
  fixedPriceQuantity: types.number(),
  replacesPriceId: types.string(),
});

export function configurationReplacePricesFromJSON(
  jsonString: string,
): SafeParseResult<ConfigurationReplacePrices, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ConfigurationReplacePrices$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ConfigurationReplacePrices' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponseOptions$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponseOptions,
    z.ZodTypeDef,
    unknown
  > = z.object({
    externalPlanId: types.string(),
    addPrices: types.optional(
      z.array(smartUnion([
        z.lazy(() => AddPrices1$inboundSchema),
        z.lazy(() =>
          AddPrices2$inboundSchema
        ),
      ])),
    ),
    alignBillingWithSubscriptionStartDate: types.optional(types.boolean()),
    couponRedemptionCode: types.optional(types.string()),
    initialPhaseOrder: types.optional(types.number()),
    metadata: types.optional(z.record(types.nullable(types.string()))),
    removePrices: types.optional(
      z.array(z.lazy(() => RemovePrices$inboundSchema)),
    ),
    replacePrices: types.optional(
      z.array(z.lazy(() => ConfigurationReplacePrices$inboundSchema)),
    ),
    startDate: types.optional(types.string()),
  });

export function buyCreditsConfigurationBillingResponseOptionsFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponseOptions,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponseOptions$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'BuyCreditsConfigurationBillingResponseOptions' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationOutput$inboundSchema: z.ZodType<
  BuyCreditsConfigurationOutput,
  z.ZodTypeDef,
  unknown
> = z.object({
  pendingSubscriptionChangeId: types.string(),
});

export function buyCreditsConfigurationOutputFromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsConfigurationOutput, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsConfigurationOutput$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationOutput' from JSON`,
  );
}

/** @internal */
export const Configuration5$inboundSchema: z.ZodType<
  Configuration5,
  z.ZodTypeDef,
  unknown
> = z.object({
  options: z.lazy(() =>
    BuyCreditsConfigurationBillingResponseOptions$inboundSchema
  ),
  output: z.lazy(() => BuyCreditsConfigurationOutput$inboundSchema),
  type: types.literal("orb_subscription"),
});

export function configuration5FromJSON(
  jsonString: string,
): SafeParseResult<Configuration5, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Configuration5$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Configuration5' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingOptions$inboundSchema: z.ZodType<
  BuyCreditsConfigurationBillingOptions,
  z.ZodTypeDef,
  unknown
> = z.object({});

export function buyCreditsConfigurationBillingOptionsFromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsConfigurationBillingOptions, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingOptions$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationBillingOptions' from JSON`,
  );
}

/** @internal */
export const ConfigurationOutput$inboundSchema: z.ZodType<
  ConfigurationOutput,
  z.ZodTypeDef,
  unknown
> = z.object({
  pendingSubscriptionChangeId: types.string(),
});

export function configurationOutputFromJSON(
  jsonString: string,
): SafeParseResult<ConfigurationOutput, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ConfigurationOutput$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ConfigurationOutput' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfiguration4$inboundSchema: z.ZodType<
  BuyCreditsConfiguration4,
  z.ZodTypeDef,
  unknown
> = z.object({
  options: z.lazy(() => BuyCreditsConfigurationBillingOptions$inboundSchema),
  output: z.lazy(() => ConfigurationOutput$inboundSchema),
  type: types.literal("orb_price_interval"),
});

export function buyCreditsConfiguration4FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsConfiguration4, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsConfiguration4$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfiguration4' from JSON`,
  );
}

/** @internal */
export const EffectiveDate2$inboundSchema: z.ZodNativeEnum<
  typeof EffectiveDate2
> = z.nativeEnum(EffectiveDate2);

/** @internal */
export const EffectiveDate1$inboundSchema: z.ZodType<
  EffectiveDate1,
  z.ZodTypeDef,
  unknown
> = z.object({});

export function effectiveDate1FromJSON(
  jsonString: string,
): SafeParseResult<EffectiveDate1, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => EffectiveDate1$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'EffectiveDate1' from JSON`,
  );
}

/** @internal */
export const EffectiveDate$inboundSchema: z.ZodType<
  EffectiveDate,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => EffectiveDate1$inboundSchema),
  EffectiveDate2$inboundSchema,
]);

export function effectiveDateFromJSON(
  jsonString: string,
): SafeParseResult<EffectiveDate, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => EffectiveDate$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'EffectiveDate' from JSON`,
  );
}

/** @internal */
export const ReplacePrices$inboundSchema: z.ZodType<
  ReplacePrices,
  z.ZodTypeDef,
  unknown
> = z.object({
  fixedPriceQuantity: types.number(),
  replacesPriceId: types.string(),
});

export function replacePricesFromJSON(
  jsonString: string,
): SafeParseResult<ReplacePrices, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ReplacePrices$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ReplacePrices' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationOptions$inboundSchema: z.ZodType<
  BuyCreditsConfigurationOptions,
  z.ZodTypeDef,
  unknown
> = z.object({
  effectiveDate: smartUnion([
    z.lazy(() => EffectiveDate1$inboundSchema),
    EffectiveDate2$inboundSchema,
  ]),
  orbSubscriptionId: types.string(),
  alignBillingWithPlanChangeDate: types.optional(types.boolean()),
  couponRedemptionCode: types.optional(types.string()),
  externalPlanId: types.optional(types.string()),
  replacePrices: types.optional(
    z.array(z.lazy(() => ReplacePrices$inboundSchema)),
  ),
});

export function buyCreditsConfigurationOptionsFromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsConfigurationOptions, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsConfigurationOptions$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationOptions' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Output$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Output,
    z.ZodTypeDef,
    unknown
  > = z.object({
    pendingSubscriptionChangeId: types.string(),
  });

export function buyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2OutputFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Output,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Output$inboundSchema
        .parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Output' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfiguration3$inboundSchema: z.ZodType<
  BuyCreditsConfiguration3,
  z.ZodTypeDef,
  unknown
> = z.object({
  options: z.lazy(() => BuyCreditsConfigurationOptions$inboundSchema),
  output: z.lazy(() =>
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Output$inboundSchema
  ),
  type: types.literal("orb_plan_change"),
});

export function buyCreditsConfiguration3FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsConfiguration3, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsConfiguration3$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfiguration3' from JSON`,
  );
}

/** @internal */
export const BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Type$inboundSchema:
  z.ZodNativeEnum<
    typeof BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Type
  > = z.nativeEnum(
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Type,
  );

/** @internal */
export const ConfigurationItems$inboundSchema: z.ZodType<
  ConfigurationItems,
  z.ZodTypeDef,
  unknown
> = z.object({
  name: types.string(),
  subtotal: types.string(),
  type:
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Type$inboundSchema,
  years: types.number(),
});

export function configurationItemsFromJSON(
  jsonString: string,
): SafeParseResult<ConfigurationItems, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ConfigurationItems$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ConfigurationItems' from JSON`,
  );
}

/** @internal */
export const ConfigurationOptions$inboundSchema: z.ZodType<
  ConfigurationOptions,
  z.ZodTypeDef,
  unknown
> = z.object({
  items: z.array(z.lazy(() => ConfigurationItems$inboundSchema)),
  orderId: types.string(),
});

export function configurationOptionsFromJSON(
  jsonString: string,
): SafeParseResult<ConfigurationOptions, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ConfigurationOptions$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ConfigurationOptions' from JSON`,
  );
}

/** @internal */
export const Configuration2$inboundSchema: z.ZodType<
  Configuration2,
  z.ZodTypeDef,
  unknown
> = z.object({
  options: z.lazy(() => ConfigurationOptions$inboundSchema),
  output: z.nullable(z.any()).optional(),
  type: types.literal("domain_name"),
});

export function configuration2FromJSON(
  jsonString: string,
): SafeParseResult<Configuration2, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Configuration2$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Configuration2' from JSON`,
  );
}

/** @internal */
export const ConfigurationCurrency$inboundSchema: z.ZodNativeEnum<
  typeof ConfigurationCurrency
> = z.nativeEnum(ConfigurationCurrency);

/** @internal */
export const BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Options$inboundSchema:
  z.ZodType<
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Options,
    z.ZodTypeDef,
    unknown
  > = z.object({
    amount: types.string(),
    currency: ConfigurationCurrency$inboundSchema,
    expirationDate: types.optional(types.string()),
  });

export function buyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2OptionsFromJSON(
  jsonString: string,
): SafeParseResult<
  BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Options,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Options$inboundSchema
        .parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Options' from JSON`,
  );
}

/** @internal */
export const Configuration1$inboundSchema: z.ZodType<
  Configuration1,
  z.ZodTypeDef,
  unknown
> = z.object({
  options: z.lazy(() =>
    BuyCreditsConfigurationBillingResponse200ApplicationJSONResponseBody2Options$inboundSchema
  ),
  output: z.nullable(z.any()).optional(),
  type: types.literal("credit_topup"),
});

export function configuration1FromJSON(
  jsonString: string,
): SafeParseResult<Configuration1, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Configuration1$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Configuration1' from JSON`,
  );
}

/** @internal */
export const BuyCreditsResponseBodyConfiguration$inboundSchema: z.ZodType<
  BuyCreditsResponseBodyConfiguration,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => Configuration1$inboundSchema),
  z.lazy(() => Configuration2$inboundSchema),
  z.lazy(() => BuyCreditsConfiguration3$inboundSchema),
  z.lazy(() => BuyCreditsConfiguration4$inboundSchema),
  z.lazy(() => Configuration5$inboundSchema),
  z.lazy(() => Configuration6$inboundSchema),
]);

export function buyCreditsResponseBodyConfigurationFromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsResponseBodyConfiguration, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) =>
      BuyCreditsResponseBodyConfiguration$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsResponseBodyConfiguration' from JSON`,
  );
}

/** @internal */
export const Currency$inboundSchema: z.ZodNativeEnum<typeof Currency> = z
  .nativeEnum(Currency);

/** @internal */
export const BuyCreditsResponseBodyType$inboundSchema: z.ZodNativeEnum<
  typeof BuyCreditsResponseBodyType
> = z.nativeEnum(BuyCreditsResponseBodyType);

/** @internal */
export const ResponseBodyProvider$inboundSchema: z.ZodType<
  ResponseBodyProvider,
  z.ZodTypeDef,
  unknown
> = z.object({
  resourceId: types.string(),
  type: BuyCreditsResponseBodyType$inboundSchema,
  currencyConversionRate: types.optional(types.string()),
  stripeSharedPaymentTokenUsed: types.optional(types.boolean()),
});

export function responseBodyProviderFromJSON(
  jsonString: string,
): SafeParseResult<ResponseBodyProvider, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ResponseBodyProvider$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ResponseBodyProvider' from JSON`,
  );
}

/** @internal */
export const BuyCreditsResponseBodyBillingStatus$inboundSchema: z.ZodNativeEnum<
  typeof BuyCreditsResponseBodyBillingStatus
> = z.nativeEnum(BuyCreditsResponseBodyBillingStatus);

/** @internal */
export const Dispute$inboundSchema: z.ZodType<Dispute, z.ZodTypeDef, unknown> =
  z.object({
    id: types.string(),
    amount: types.string(),
    createdAt: types.string(),
    currency: types.string(),
    providerId: types.string(),
    reason: types.nullable(types.string()),
    status: types.string(),
    updatedAt: types.string(),
  });

export function disputeFromJSON(
  jsonString: string,
): SafeParseResult<Dispute, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Dispute$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Dispute' from JSON`,
  );
}

/** @internal */
export const LineItems$inboundSchema: z.ZodType<
  LineItems,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  description: types.string(),
  name: types.string(),
  productId: types.string(),
  quantity: types.string(),
  unitAmount: types.string(),
  metadata: types.optional(z.record(types.string())),
  productAlias: types.optional(types.string()),
  refund: types.optional(types.string()),
});

export function lineItemsFromJSON(
  jsonString: string,
): SafeParseResult<LineItems, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => LineItems$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'LineItems' from JSON`,
  );
}

/** @internal */
export const PurchaseIntent$inboundSchema: z.ZodType<
  PurchaseIntent,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  configuration: z.union([
    z.lazy(() => Configuration1$inboundSchema),
    z.lazy(() => Configuration2$inboundSchema),
    z.lazy(() => BuyCreditsConfiguration3$inboundSchema),
    z.lazy(() => BuyCreditsConfiguration4$inboundSchema),
    z.lazy(() => Configuration5$inboundSchema),
    z.lazy(() => Configuration6$inboundSchema),
  ]),
  createdAt: types.string(),
  currency: Currency$inboundSchema,
  ownerId: types.string(),
  provider: z.lazy(() => ResponseBodyProvider$inboundSchema),
  status: BuyCreditsResponseBodyBillingStatus$inboundSchema,
  subtotal: types.string(),
  tax: types.string(),
  total: types.string(),
  updatedAt: types.string(),
  dispute: types.optional(z.lazy(() => Dispute$inboundSchema)),
  lineItems: types.optional(z.array(z.lazy(() => LineItems$inboundSchema))),
  metadata: types.optional(z.record(types.string())),
  refund: types.optional(types.string()),
  returnUrl: types.optional(types.string()),
});

export function purchaseIntentFromJSON(
  jsonString: string,
): SafeParseResult<PurchaseIntent, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => PurchaseIntent$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'PurchaseIntent' from JSON`,
  );
}

/** @internal */
export const BuyCreditsResponseBody2$inboundSchema: z.ZodType<
  BuyCreditsResponseBody2,
  z.ZodTypeDef,
  unknown
> = z.object({
  purchaseIntent: z.lazy(() => PurchaseIntent$inboundSchema),
});

export function buyCreditsResponseBody2FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsResponseBody2, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsResponseBody2$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsResponseBody2' from JSON`,
  );
}

/** @internal */
export const BuyCreditsResponseBody1$inboundSchema: z.ZodType<
  BuyCreditsResponseBody1,
  z.ZodTypeDef,
  unknown
> = z.object({
  checkoutSessionId: types.string(),
  checkoutSessionUrl: types.string(),
});

export function buyCreditsResponseBody1FromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsResponseBody1, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsResponseBody1$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsResponseBody1' from JSON`,
  );
}

/** @internal */
export const BuyCreditsResponseBody$inboundSchema: z.ZodType<
  BuyCreditsResponseBody,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => BuyCreditsResponseBody1$inboundSchema),
  z.lazy(() => BuyCreditsResponseBody2$inboundSchema),
  z.lazy(() => BuyCreditsResponseBody3$inboundSchema),
]);

export function buyCreditsResponseBodyFromJSON(
  jsonString: string,
): SafeParseResult<BuyCreditsResponseBody, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BuyCreditsResponseBody$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BuyCreditsResponseBody' from JSON`,
  );
}
