/*
 * 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 { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  CustomerPaymentMethodCreateRequiresActionResponse,
  CustomerPaymentMethodCreateRequiresActionResponse$inboundSchema,
} from "./customerpaymentmethodcreaterequiresactionresponse.js";
import {
  CustomerPaymentMethodCreateSucceededResponse,
  CustomerPaymentMethodCreateSucceededResponse$inboundSchema,
} from "./customerpaymentmethodcreatesucceededresponse.js";

export type CustomerPaymentMethodCreateResponse =
  | CustomerPaymentMethodCreateRequiresActionResponse
  | CustomerPaymentMethodCreateSucceededResponse;

/** @internal */
export const CustomerPaymentMethodCreateResponse$inboundSchema: z.ZodMiniType<
  CustomerPaymentMethodCreateResponse,
  unknown
> = z.union([
  CustomerPaymentMethodCreateRequiresActionResponse$inboundSchema,
  CustomerPaymentMethodCreateSucceededResponse$inboundSchema,
]);

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