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

/**
 * Sent when a benefit grant is updated.
 *
 * @remarks
 *
 * **Discord & Slack support:** Basic
 */
export type WebhookBenefitGrantUpdatedPayload = {
  type: "benefit_grant.updated";
  timestamp: Date;
  data: BenefitGrantWebhook;
};

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

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

export function webhookBenefitGrantUpdatedPayloadToJSON(
  webhookBenefitGrantUpdatedPayload: WebhookBenefitGrantUpdatedPayload,
): string {
  return JSON.stringify(
    WebhookBenefitGrantUpdatedPayload$outboundSchema.parse(
      webhookBenefitGrantUpdatedPayload,
    ),
  );
}
export function webhookBenefitGrantUpdatedPayloadFromJSON(
  jsonString: string,
): SafeParseResult<WebhookBenefitGrantUpdatedPayload, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => WebhookBenefitGrantUpdatedPayload$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'WebhookBenefitGrantUpdatedPayload' from JSON`,
  );
}
