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

import * as z from "zod/v4-mini";
import { remap as remap$ } from "../../lib/primitives.js";
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 { AddressDict, AddressDict$inboundSchema } from "./addressdict.js";

export type CustomerUpdatedFieldsMetadata = string | number | boolean;

export type CustomerUpdatedFields = {
  name?: string | null | undefined;
  billingName?: string | null | undefined;
  email?: string | null | undefined;
  billingAddress?: AddressDict | null | undefined;
  taxId?: string | null | undefined;
  metadata?: { [k: string]: string | number | boolean } | null | undefined;
};

/** @internal */
export const CustomerUpdatedFieldsMetadata$inboundSchema: z.ZodMiniType<
  CustomerUpdatedFieldsMetadata,
  unknown
> = smartUnion([z.string(), z.int(), z.boolean()]);

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

/** @internal */
export const CustomerUpdatedFields$inboundSchema: z.ZodMiniType<
  CustomerUpdatedFields,
  unknown
> = z.pipe(
  z.object({
    name: z.optional(z.nullable(z.string())),
    billing_name: z.optional(z.nullable(z.string())),
    email: z.optional(z.nullable(z.string())),
    billing_address: z.optional(z.nullable(AddressDict$inboundSchema)),
    tax_id: z.optional(z.nullable(z.string())),
    metadata: z.optional(
      z.nullable(
        z.record(z.string(), smartUnion([z.string(), z.int(), z.boolean()])),
      ),
    ),
  }),
  z.transform((v) => {
    return remap$(v, {
      "billing_name": "billingName",
      "billing_address": "billingAddress",
      "tax_id": "taxId",
    });
  }),
);

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