/*
 * 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 {
  Customer,
  Customer$inboundSchema,
  Customer$Outbound,
  Customer$outboundSchema,
} from "./customer.js";

/**
 * Sent when a customer is updated.
 *
 * @remarks
 *
 * This event is fired when the customer details are updated.
 *
 * If you want to be notified when a customer subscription or benefit state changes, you should listen to the `customer_state_changed` event.
 *
 * **Discord & Slack support:** Basic
 */
export type WebhookCustomerUpdatedPayload = {
  type: "customer.updated";
  timestamp: Date;
  data: Customer;
};

/** @internal */
export const WebhookCustomerUpdatedPayload$inboundSchema: z.ZodMiniType<
  WebhookCustomerUpdatedPayload,
  unknown
> = z.object({
  type: z.literal("customer.updated"),
  timestamp: z.pipe(
    z.iso.datetime({ offset: true }),
    z.transform(v => new Date(v)),
  ),
  data: Customer$inboundSchema,
});
/** @internal */
export type WebhookCustomerUpdatedPayload$Outbound = {
  type: "customer.updated";
  timestamp: string;
  data: Customer$Outbound;
};

/** @internal */
export const WebhookCustomerUpdatedPayload$outboundSchema: z.ZodMiniType<
  WebhookCustomerUpdatedPayload$Outbound,
  WebhookCustomerUpdatedPayload
> = z.object({
  type: z.literal("customer.updated"),
  timestamp: z.pipe(z.date(), z.transform(v => v.toISOString())),
  data: Customer$outboundSchema,
});

export function webhookCustomerUpdatedPayloadToJSON(
  webhookCustomerUpdatedPayload: WebhookCustomerUpdatedPayload,
): string {
  return JSON.stringify(
    WebhookCustomerUpdatedPayload$outboundSchema.parse(
      webhookCustomerUpdatedPayload,
    ),
  );
}
export function webhookCustomerUpdatedPayloadFromJSON(
  jsonString: string,
): SafeParseResult<WebhookCustomerUpdatedPayload, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => WebhookCustomerUpdatedPayload$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'WebhookCustomerUpdatedPayload' from JSON`,
  );
}
