/*
 * 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 {
  DiscountFixedOnceForeverDuration,
  DiscountFixedOnceForeverDuration$inboundSchema,
} from "./discountfixedonceforeverduration.js";
import {
  DiscountFixedRepeatDuration,
  DiscountFixedRepeatDuration$inboundSchema,
} from "./discountfixedrepeatduration.js";
import {
  DiscountPercentageOnceForeverDuration,
  DiscountPercentageOnceForeverDuration$inboundSchema,
} from "./discountpercentageonceforeverduration.js";
import {
  DiscountPercentageRepeatDuration,
  DiscountPercentageRepeatDuration$inboundSchema,
} from "./discountpercentagerepeatduration.js";

export type Discount =
  | DiscountFixedRepeatDuration
  | DiscountFixedOnceForeverDuration
  | DiscountPercentageRepeatDuration
  | DiscountPercentageOnceForeverDuration;

/** @internal */
export const Discount$inboundSchema: z.ZodMiniType<Discount, unknown> =
  smartUnion([
    DiscountFixedRepeatDuration$inboundSchema,
    DiscountFixedOnceForeverDuration$inboundSchema,
    DiscountPercentageRepeatDuration$inboundSchema,
    DiscountPercentageOnceForeverDuration$inboundSchema,
  ]);

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