/*
 * 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 {
  DiscountDuration,
  DiscountDuration$inboundSchema,
  DiscountDuration$outboundSchema,
} from "./discountduration.js";
import {
  DiscountType,
  DiscountType$inboundSchema,
  DiscountType$outboundSchema,
} from "./discounttype.js";

/**
 * Schema for a fixed amount discount that is applied once or forever.
 */
export type CheckoutDiscountFixedOnceForeverDuration = {
  duration: DiscountDuration;
  type: DiscountType;
  /**
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  amount: number;
  /**
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  currency: string;
  /**
   * Map of currency to fixed amount to discount from the total.
   */
  amounts: { [k: string]: number };
  /**
   * The ID of the object.
   */
  id: string;
  name: string;
  code: string | null;
};

/** @internal */
export const CheckoutDiscountFixedOnceForeverDuration$inboundSchema:
  z.ZodMiniType<CheckoutDiscountFixedOnceForeverDuration, unknown> = z.object({
    duration: DiscountDuration$inboundSchema,
    type: DiscountType$inboundSchema,
    amount: z.int(),
    currency: z.string(),
    amounts: z.record(z.string(), z.int()),
    id: z.string(),
    name: z.string(),
    code: z.nullable(z.string()),
  });
/** @internal */
export type CheckoutDiscountFixedOnceForeverDuration$Outbound = {
  duration: string;
  type: string;
  amount: number;
  currency: string;
  amounts: { [k: string]: number };
  id: string;
  name: string;
  code: string | null;
};

/** @internal */
export const CheckoutDiscountFixedOnceForeverDuration$outboundSchema:
  z.ZodMiniType<
    CheckoutDiscountFixedOnceForeverDuration$Outbound,
    CheckoutDiscountFixedOnceForeverDuration
  > = z.object({
    duration: DiscountDuration$outboundSchema,
    type: DiscountType$outboundSchema,
    amount: z.int(),
    currency: z.string(),
    amounts: z.record(z.string(), z.int()),
    id: z.string(),
    name: z.string(),
    code: z.nullable(z.string()),
  });

export function checkoutDiscountFixedOnceForeverDurationToJSON(
  checkoutDiscountFixedOnceForeverDuration:
    CheckoutDiscountFixedOnceForeverDuration,
): string {
  return JSON.stringify(
    CheckoutDiscountFixedOnceForeverDuration$outboundSchema.parse(
      checkoutDiscountFixedOnceForeverDuration,
    ),
  );
}
export function checkoutDiscountFixedOnceForeverDurationFromJSON(
  jsonString: string,
): SafeParseResult<
  CheckoutDiscountFixedOnceForeverDuration,
  SDKValidationError
> {
  return safeParse(
    jsonString,
    (x) =>
      CheckoutDiscountFixedOnceForeverDuration$inboundSchema.parse(
        JSON.parse(x),
      ),
    `Failed to parse 'CheckoutDiscountFixedOnceForeverDuration' from JSON`,
  );
}
