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

/**
 * Sent when a customer revokes a pending cancellation.
 *
 * @remarks
 *
 * When a customer cancels with "at period end", they retain access until the
 * subscription would renew. During this time, they can change their mind and
 * undo the cancellation. This event is triggered when they do so.
 *
 * **Discord & Slack support:** Full
 */
export type WebhookSubscriptionUncanceledPayload = {
  type: "subscription.uncanceled";
  timestamp: Date;
  data: Subscription;
};

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

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

export function webhookSubscriptionUncanceledPayloadToJSON(
  webhookSubscriptionUncanceledPayload: WebhookSubscriptionUncanceledPayload,
): string {
  return JSON.stringify(
    WebhookSubscriptionUncanceledPayload$outboundSchema.parse(
      webhookSubscriptionUncanceledPayload,
    ),
  );
}
export function webhookSubscriptionUncanceledPayloadFromJSON(
  jsonString: string,
): SafeParseResult<WebhookSubscriptionUncanceledPayload, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) =>
      WebhookSubscriptionUncanceledPayload$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'WebhookSubscriptionUncanceledPayload' from JSON`,
  );
}
