/*
 * 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 {
  CustomerStateIndividual,
  CustomerStateIndividual$inboundSchema,
  CustomerStateIndividual$Outbound,
  CustomerStateIndividual$outboundSchema,
} from "./customerstateindividual.js";
import {
  CustomerStateTeam,
  CustomerStateTeam$inboundSchema,
  CustomerStateTeam$Outbound,
  CustomerStateTeam$outboundSchema,
} from "./customerstateteam.js";

export type CustomerState = CustomerStateIndividual | CustomerStateTeam;

/** @internal */
export const CustomerState$inboundSchema: z.ZodMiniType<
  CustomerState,
  unknown
> = z.union([
  CustomerStateIndividual$inboundSchema,
  CustomerStateTeam$inboundSchema,
]);
/** @internal */
export type CustomerState$Outbound =
  | CustomerStateIndividual$Outbound
  | CustomerStateTeam$Outbound;

/** @internal */
export const CustomerState$outboundSchema: z.ZodMiniType<
  CustomerState$Outbound,
  CustomerState
> = z.union([
  CustomerStateIndividual$outboundSchema,
  CustomerStateTeam$outboundSchema,
]);

export function customerStateToJSON(customerState: CustomerState): string {
  return JSON.stringify(CustomerState$outboundSchema.parse(customerState));
}
export function customerStateFromJSON(
  jsonString: string,
): SafeParseResult<CustomerState, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => CustomerState$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CustomerState' from JSON`,
  );
}
