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

import * as z from "zod/v4-mini";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { smartUnion } from "../../types/smartUnion.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  PaymentMethodCard,
  PaymentMethodCard$inboundSchema,
} from "./paymentmethodcard.js";
import {
  PaymentMethodGeneric,
  PaymentMethodGeneric$inboundSchema,
} from "./paymentmethodgeneric.js";

export type CustomerPaymentMethod = PaymentMethodCard | PaymentMethodGeneric;

/** @internal */
export const CustomerPaymentMethod$inboundSchema: z.ZodMiniType<
  CustomerPaymentMethod,
  unknown
> = smartUnion([
  PaymentMethodCard$inboundSchema,
  PaymentMethodGeneric$inboundSchema,
]);

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