/*
 * 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 {
  CustomerPaymentMethodCard,
  CustomerPaymentMethodCard$inboundSchema,
} from "./customerpaymentmethodcard.js";
import {
  CustomerPaymentMethodGeneric,
  CustomerPaymentMethodGeneric$inboundSchema,
} from "./customerpaymentmethodgeneric.js";

export type PaymentMethod =
  | CustomerPaymentMethodCard
  | CustomerPaymentMethodGeneric;

/** @internal */
export const PaymentMethod$inboundSchema: z.ZodMiniType<
  PaymentMethod,
  unknown
> = smartUnion([
  CustomerPaymentMethodCard$inboundSchema,
  CustomerPaymentMethodGeneric$inboundSchema,
]);

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