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

export type CustomerUpdatedMetadata = {
  customerId: string;
  customerEmail: string | null;
  customerName: string | null;
  customerExternalId: string | null;
  updatedFields: CustomerUpdatedFields;
};

/** @internal */
export const CustomerUpdatedMetadata$inboundSchema: z.ZodMiniType<
  CustomerUpdatedMetadata,
  unknown
> = z.pipe(
  z.object({
    customer_id: z.string(),
    customer_email: z.nullable(z.string()),
    customer_name: z.nullable(z.string()),
    customer_external_id: z.nullable(z.string()),
    updated_fields: CustomerUpdatedFields$inboundSchema,
  }),
  z.transform((v) => {
    return remap$(v, {
      "customer_id": "customerId",
      "customer_email": "customerEmail",
      "customer_name": "customerName",
      "customer_external_id": "customerExternalId",
      "updated_fields": "updatedFields",
    });
  }),
);

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