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

/**
 * Sent when a refund is updated.
 *
 * @remarks
 *
 * **Discord & Slack support:** Full
 */
export type WebhookRefundUpdatedPayload = {
  type: "refund.updated";
  timestamp: Date;
  data: Refund;
};

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

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

export function webhookRefundUpdatedPayloadToJSON(
  webhookRefundUpdatedPayload: WebhookRefundUpdatedPayload,
): string {
  return JSON.stringify(
    WebhookRefundUpdatedPayload$outboundSchema.parse(
      webhookRefundUpdatedPayload,
    ),
  );
}
export function webhookRefundUpdatedPayloadFromJSON(
  jsonString: string,
): SafeParseResult<WebhookRefundUpdatedPayload, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => WebhookRefundUpdatedPayload$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'WebhookRefundUpdatedPayload' from JSON`,
  );
}
