/*
 * 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 { smartUnion } from "../../types/smartUnion.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  BenefitGrantCustomWebhook,
  BenefitGrantCustomWebhook$inboundSchema,
  BenefitGrantCustomWebhook$Outbound,
  BenefitGrantCustomWebhook$outboundSchema,
} from "./benefitgrantcustomwebhook.js";
import {
  BenefitGrantDiscordWebhook,
  BenefitGrantDiscordWebhook$inboundSchema,
  BenefitGrantDiscordWebhook$Outbound,
  BenefitGrantDiscordWebhook$outboundSchema,
} from "./benefitgrantdiscordwebhook.js";
import {
  BenefitGrantDownloadablesWebhook,
  BenefitGrantDownloadablesWebhook$inboundSchema,
  BenefitGrantDownloadablesWebhook$Outbound,
  BenefitGrantDownloadablesWebhook$outboundSchema,
} from "./benefitgrantdownloadableswebhook.js";
import {
  BenefitGrantFeatureFlagWebhook,
  BenefitGrantFeatureFlagWebhook$inboundSchema,
  BenefitGrantFeatureFlagWebhook$Outbound,
  BenefitGrantFeatureFlagWebhook$outboundSchema,
} from "./benefitgrantfeatureflagwebhook.js";
import {
  BenefitGrantGitHubRepositoryWebhook,
  BenefitGrantGitHubRepositoryWebhook$inboundSchema,
  BenefitGrantGitHubRepositoryWebhook$Outbound,
  BenefitGrantGitHubRepositoryWebhook$outboundSchema,
} from "./benefitgrantgithubrepositorywebhook.js";
import {
  BenefitGrantLicenseKeysWebhook,
  BenefitGrantLicenseKeysWebhook$inboundSchema,
  BenefitGrantLicenseKeysWebhook$Outbound,
  BenefitGrantLicenseKeysWebhook$outboundSchema,
} from "./benefitgrantlicensekeyswebhook.js";
import {
  BenefitGrantMeterCreditWebhook,
  BenefitGrantMeterCreditWebhook$inboundSchema,
  BenefitGrantMeterCreditWebhook$Outbound,
  BenefitGrantMeterCreditWebhook$outboundSchema,
} from "./benefitgrantmetercreditwebhook.js";
import {
  BenefitGrantSlackSharedChannelWebhook,
  BenefitGrantSlackSharedChannelWebhook$inboundSchema,
  BenefitGrantSlackSharedChannelWebhook$Outbound,
  BenefitGrantSlackSharedChannelWebhook$outboundSchema,
} from "./benefitgrantslacksharedchannelwebhook.js";

export type BenefitGrantWebhook =
  | BenefitGrantDiscordWebhook
  | BenefitGrantCustomWebhook
  | BenefitGrantGitHubRepositoryWebhook
  | BenefitGrantDownloadablesWebhook
  | BenefitGrantLicenseKeysWebhook
  | BenefitGrantMeterCreditWebhook
  | BenefitGrantFeatureFlagWebhook
  | BenefitGrantSlackSharedChannelWebhook;

/** @internal */
export const BenefitGrantWebhook$inboundSchema: z.ZodMiniType<
  BenefitGrantWebhook,
  unknown
> = smartUnion([
  BenefitGrantDiscordWebhook$inboundSchema,
  BenefitGrantCustomWebhook$inboundSchema,
  BenefitGrantGitHubRepositoryWebhook$inboundSchema,
  BenefitGrantDownloadablesWebhook$inboundSchema,
  BenefitGrantLicenseKeysWebhook$inboundSchema,
  BenefitGrantMeterCreditWebhook$inboundSchema,
  BenefitGrantFeatureFlagWebhook$inboundSchema,
  BenefitGrantSlackSharedChannelWebhook$inboundSchema,
]);
/** @internal */
export type BenefitGrantWebhook$Outbound =
  | BenefitGrantDiscordWebhook$Outbound
  | BenefitGrantCustomWebhook$Outbound
  | BenefitGrantGitHubRepositoryWebhook$Outbound
  | BenefitGrantDownloadablesWebhook$Outbound
  | BenefitGrantLicenseKeysWebhook$Outbound
  | BenefitGrantMeterCreditWebhook$Outbound
  | BenefitGrantFeatureFlagWebhook$Outbound
  | BenefitGrantSlackSharedChannelWebhook$Outbound;

/** @internal */
export const BenefitGrantWebhook$outboundSchema: z.ZodMiniType<
  BenefitGrantWebhook$Outbound,
  BenefitGrantWebhook
> = smartUnion([
  BenefitGrantDiscordWebhook$outboundSchema,
  BenefitGrantCustomWebhook$outboundSchema,
  BenefitGrantGitHubRepositoryWebhook$outboundSchema,
  BenefitGrantDownloadablesWebhook$outboundSchema,
  BenefitGrantLicenseKeysWebhook$outboundSchema,
  BenefitGrantMeterCreditWebhook$outboundSchema,
  BenefitGrantFeatureFlagWebhook$outboundSchema,
  BenefitGrantSlackSharedChannelWebhook$outboundSchema,
]);

export function benefitGrantWebhookToJSON(
  benefitGrantWebhook: BenefitGrantWebhook,
): string {
  return JSON.stringify(
    BenefitGrantWebhook$outboundSchema.parse(benefitGrantWebhook),
  );
}
export function benefitGrantWebhookFromJSON(
  jsonString: string,
): SafeParseResult<BenefitGrantWebhook, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BenefitGrantWebhook$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BenefitGrantWebhook' from JSON`,
  );
}
