/*
 * 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 {
  BalanceCreditOrderEvent,
  BalanceCreditOrderEvent$inboundSchema,
} from "./balancecreditorderevent.js";
import {
  BalanceDisputeEvent,
  BalanceDisputeEvent$inboundSchema,
} from "./balancedisputeevent.js";
import {
  BalanceDisputeReversalEvent,
  BalanceDisputeReversalEvent$inboundSchema,
} from "./balancedisputereversalevent.js";
import {
  BalanceOrderEvent,
  BalanceOrderEvent$inboundSchema,
} from "./balanceorderevent.js";
import {
  BalanceRefundEvent,
  BalanceRefundEvent$inboundSchema,
} from "./balancerefundevent.js";
import {
  BalanceRefundReversalEvent,
  BalanceRefundReversalEvent$inboundSchema,
} from "./balancerefundreversalevent.js";
import {
  BenefitCycledEvent,
  BenefitCycledEvent$inboundSchema,
} from "./benefitcycledevent.js";
import {
  BenefitGrantedEvent,
  BenefitGrantedEvent$inboundSchema,
} from "./benefitgrantedevent.js";
import {
  BenefitRevokedEvent,
  BenefitRevokedEvent$inboundSchema,
} from "./benefitrevokedevent.js";
import {
  BenefitUpdatedEvent,
  BenefitUpdatedEvent$inboundSchema,
} from "./benefitupdatedevent.js";
import {
  CheckoutCreatedEvent,
  CheckoutCreatedEvent$inboundSchema,
} from "./checkoutcreatedevent.js";
import {
  CustomerCreatedEvent,
  CustomerCreatedEvent$inboundSchema,
} from "./customercreatedevent.js";
import {
  CustomerDeletedEvent,
  CustomerDeletedEvent$inboundSchema,
} from "./customerdeletedevent.js";
import {
  CustomerUpdatedEvent,
  CustomerUpdatedEvent$inboundSchema,
} from "./customerupdatedevent.js";
import {
  MeterCreditEvent,
  MeterCreditEvent$inboundSchema,
} from "./metercreditevent.js";
import {
  MeterResetEvent,
  MeterResetEvent$inboundSchema,
} from "./meterresetevent.js";
import {
  OrderPaidEvent,
  OrderPaidEvent$inboundSchema,
} from "./orderpaidevent.js";
import {
  OrderRefundedEvent,
  OrderRefundedEvent$inboundSchema,
} from "./orderrefundedevent.js";
import {
  OrderVoidedEvent,
  OrderVoidedEvent$inboundSchema,
} from "./ordervoidedevent.js";
import {
  SubscriptionBillingPeriodUpdatedEvent,
  SubscriptionBillingPeriodUpdatedEvent$inboundSchema,
} from "./subscriptionbillingperiodupdatedevent.js";
import {
  SubscriptionCanceledEvent,
  SubscriptionCanceledEvent$inboundSchema,
} from "./subscriptioncanceledevent.js";
import {
  SubscriptionCreatedEvent,
  SubscriptionCreatedEvent$inboundSchema,
} from "./subscriptioncreatedevent.js";
import {
  SubscriptionCycledEvent,
  SubscriptionCycledEvent$inboundSchema,
} from "./subscriptioncycledevent.js";
import {
  SubscriptionPastDueEvent,
  SubscriptionPastDueEvent$inboundSchema,
} from "./subscriptionpastdueevent.js";
import {
  SubscriptionPausedEvent,
  SubscriptionPausedEvent$inboundSchema,
} from "./subscriptionpausedevent.js";
import {
  SubscriptionProductUpdatedEvent,
  SubscriptionProductUpdatedEvent$inboundSchema,
} from "./subscriptionproductupdatedevent.js";
import {
  SubscriptionReactivatedEvent,
  SubscriptionReactivatedEvent$inboundSchema,
} from "./subscriptionreactivatedevent.js";
import {
  SubscriptionResumedEvent,
  SubscriptionResumedEvent$inboundSchema,
} from "./subscriptionresumedevent.js";
import {
  SubscriptionRevokedEvent,
  SubscriptionRevokedEvent$inboundSchema,
} from "./subscriptionrevokedevent.js";
import {
  SubscriptionSeatsUpdatedEvent,
  SubscriptionSeatsUpdatedEvent$inboundSchema,
} from "./subscriptionseatsupdatedevent.js";
import {
  SubscriptionUncanceledEvent,
  SubscriptionUncanceledEvent$inboundSchema,
} from "./subscriptionuncanceledevent.js";
import {
  SubscriptionUpdateClearedEvent,
  SubscriptionUpdateClearedEvent$inboundSchema,
} from "./subscriptionupdateclearedevent.js";
import {
  SubscriptionUpdatedEvent,
  SubscriptionUpdatedEvent$inboundSchema,
} from "./subscriptionupdatedevent.js";

export type SystemEvent =
  | BalanceCreditOrderEvent
  | BalanceDisputeEvent
  | BalanceDisputeReversalEvent
  | BalanceOrderEvent
  | BalanceRefundEvent
  | BalanceRefundReversalEvent
  | BenefitCycledEvent
  | BenefitGrantedEvent
  | BenefitRevokedEvent
  | BenefitUpdatedEvent
  | CheckoutCreatedEvent
  | CustomerCreatedEvent
  | CustomerDeletedEvent
  | CustomerUpdatedEvent
  | MeterCreditEvent
  | MeterResetEvent
  | OrderPaidEvent
  | OrderRefundedEvent
  | OrderVoidedEvent
  | SubscriptionBillingPeriodUpdatedEvent
  | SubscriptionCanceledEvent
  | SubscriptionCreatedEvent
  | SubscriptionCycledEvent
  | SubscriptionPastDueEvent
  | SubscriptionPausedEvent
  | SubscriptionProductUpdatedEvent
  | SubscriptionReactivatedEvent
  | SubscriptionResumedEvent
  | SubscriptionRevokedEvent
  | SubscriptionSeatsUpdatedEvent
  | SubscriptionUncanceledEvent
  | SubscriptionUpdateClearedEvent
  | SubscriptionUpdatedEvent;

/** @internal */
export const SystemEvent$inboundSchema: z.ZodMiniType<SystemEvent, unknown> = z
  .union([
    BalanceCreditOrderEvent$inboundSchema,
    BalanceDisputeEvent$inboundSchema,
    BalanceDisputeReversalEvent$inboundSchema,
    BalanceOrderEvent$inboundSchema,
    BalanceRefundEvent$inboundSchema,
    BalanceRefundReversalEvent$inboundSchema,
    BenefitCycledEvent$inboundSchema,
    BenefitGrantedEvent$inboundSchema,
    BenefitRevokedEvent$inboundSchema,
    BenefitUpdatedEvent$inboundSchema,
    CheckoutCreatedEvent$inboundSchema,
    CustomerCreatedEvent$inboundSchema,
    CustomerDeletedEvent$inboundSchema,
    CustomerUpdatedEvent$inboundSchema,
    MeterCreditEvent$inboundSchema,
    MeterResetEvent$inboundSchema,
    OrderPaidEvent$inboundSchema,
    OrderRefundedEvent$inboundSchema,
    OrderVoidedEvent$inboundSchema,
    SubscriptionBillingPeriodUpdatedEvent$inboundSchema,
    SubscriptionCanceledEvent$inboundSchema,
    SubscriptionCreatedEvent$inboundSchema,
    SubscriptionCycledEvent$inboundSchema,
    SubscriptionPastDueEvent$inboundSchema,
    SubscriptionPausedEvent$inboundSchema,
    SubscriptionProductUpdatedEvent$inboundSchema,
    SubscriptionReactivatedEvent$inboundSchema,
    SubscriptionResumedEvent$inboundSchema,
    SubscriptionRevokedEvent$inboundSchema,
    SubscriptionSeatsUpdatedEvent$inboundSchema,
    SubscriptionUncanceledEvent$inboundSchema,
    SubscriptionUpdateClearedEvent$inboundSchema,
    SubscriptionUpdatedEvent$inboundSchema,
  ]);

export function systemEventFromJSON(
  jsonString: string,
): SafeParseResult<SystemEvent, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => SystemEvent$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'SystemEvent' from JSON`,
  );
}
