/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v4-mini";
import { remap as remap$ } from "../../lib/primitives.js";
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 on every invoice
 *
 * @remarks
 * for a certain number of months.
 */
export type CheckoutDiscountFixedRepeatDuration = {
  duration: DiscountDuration;
  durationInMonths: number;
  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 CheckoutDiscountFixedRepeatDuration$inboundSchema: z.ZodMiniType<
  CheckoutDiscountFixedRepeatDuration,
  unknown
> = z.pipe(
  z.object({
    duration: DiscountDuration$inboundSchema,
    duration_in_months: z.int(),
    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()),
  }),
  z.transform((v) => {
    return remap$(v, {
      "duration_in_months": "durationInMonths",
    });
  }),
);
/** @internal */
export type CheckoutDiscountFixedRepeatDuration$Outbound = {
  duration: string;
  duration_in_months: number;
  type: string;
  amount: number;
  currency: string;
  amounts: { [k: string]: number };
  id: string;
  name: string;
  code: string | null;
};

/** @internal */
export const CheckoutDiscountFixedRepeatDuration$outboundSchema: z.ZodMiniType<
  CheckoutDiscountFixedRepeatDuration$Outbound,
  CheckoutDiscountFixedRepeatDuration
> = z.pipe(
  z.object({
    duration: DiscountDuration$outboundSchema,
    durationInMonths: z.int(),
    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()),
  }),
  z.transform((v) => {
    return remap$(v, {
      durationInMonths: "duration_in_months",
    });
  }),
);

export function checkoutDiscountFixedRepeatDurationToJSON(
  checkoutDiscountFixedRepeatDuration: CheckoutDiscountFixedRepeatDuration,
): string {
  return JSON.stringify(
    CheckoutDiscountFixedRepeatDuration$outboundSchema.parse(
      checkoutDiscountFixedRepeatDuration,
    ),
  );
}
export function checkoutDiscountFixedRepeatDurationFromJSON(
  jsonString: string,
): SafeParseResult<CheckoutDiscountFixedRepeatDuration, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) =>
      CheckoutDiscountFixedRepeatDuration$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CheckoutDiscountFixedRepeatDuration' from JSON`,
  );
}
