/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { EnvironmentMode, EnvironmentMode$inboundSchema, EnvironmentMode$outboundSchema, } from "./environmentmode.js"; /** * The status of the discount (e.g., active, inactive). */ export const DiscountEntityStatus = { Deleted: "deleted", Active: "active", Draft: "draft", Expired: "expired", Scheduled: "scheduled", } as const; /** * The status of the discount (e.g., active, inactive). */ export type DiscountEntityStatus = ClosedEnum; /** * The type of the discount, either "percentage" or "fixed". */ export const Type = { Percentage: "percentage", Fixed: "fixed", } as const; /** * The type of the discount, either "percentage" or "fixed". */ export type Type = ClosedEnum; /** * The duration type for the discount. */ export const Duration = { Forever: "forever", Once: "once", Repeating: "repeating", } as const; /** * The duration type for the discount. */ export type Duration = ClosedEnum; export type DiscountEntity = { /** * Unique identifier for the object. */ id: string; /** * String representing the environment. */ mode: EnvironmentMode; /** * A string representing the object’s type. Objects of the same type share the same value. */ object: string; /** * The status of the discount (e.g., active, inactive). */ status: DiscountEntityStatus; /** * The name of the discount. */ name: string; /** * The discount code. A unique identifier for the discount. */ code: string; /** * The type of the discount, either "percentage" or "fixed". */ type: Type; /** * The amount of the discount. Can be a percentage or a fixed amount. */ amount?: number | undefined; /** * The currency of the discount. Only required if type is "fixed". */ currency?: string | undefined; /** * The percentage of the discount. Only applicable if type is "percentage". */ percentage?: number | undefined; /** * The expiry date of the discount. */ expiryDate?: Date | undefined; /** * The maximum number of redemptions allowed for the discount. */ maxRedemptions?: number | undefined; /** * The duration type for the discount. */ duration?: Duration | undefined; /** * The number of months the discount is valid for. Only applicable if the duration is "repeating" and the product is a subscription. */ durationInMonths?: number | undefined; /** * The list of product IDs to which this discount applies. */ appliesToProducts?: Array | undefined; /** * The number of times this discount has been redeemed. */ redeemCount?: number | undefined; }; /** @internal */ export const DiscountEntityStatus$inboundSchema: z.ZodNativeEnum< typeof DiscountEntityStatus > = z.nativeEnum(DiscountEntityStatus); /** @internal */ export const DiscountEntityStatus$outboundSchema: z.ZodNativeEnum< typeof DiscountEntityStatus > = DiscountEntityStatus$inboundSchema; /** @internal */ export const Type$inboundSchema: z.ZodNativeEnum = z.nativeEnum( Type, ); /** @internal */ export const Type$outboundSchema: z.ZodNativeEnum = Type$inboundSchema; /** @internal */ export const Duration$inboundSchema: z.ZodNativeEnum = z .nativeEnum(Duration); /** @internal */ export const Duration$outboundSchema: z.ZodNativeEnum = Duration$inboundSchema; /** @internal */ export const DiscountEntity$inboundSchema: z.ZodType< DiscountEntity, z.ZodTypeDef, unknown > = z.object({ id: z.string(), mode: EnvironmentMode$inboundSchema, object: z.string(), status: DiscountEntityStatus$inboundSchema, name: z.string(), code: z.string(), type: Type$inboundSchema, amount: z.number().optional(), currency: z.string().optional(), percentage: z.number().optional(), expiry_date: z.string().datetime({ offset: true }).transform(v => new Date(v)) .optional(), max_redemptions: z.number().optional(), duration: Duration$inboundSchema.optional(), duration_in_months: z.number().optional(), applies_to_products: z.array(z.string()).optional(), redeem_count: z.number().optional(), }).transform((v) => { return remap$(v, { "expiry_date": "expiryDate", "max_redemptions": "maxRedemptions", "duration_in_months": "durationInMonths", "applies_to_products": "appliesToProducts", "redeem_count": "redeemCount", }); }); /** @internal */ export type DiscountEntity$Outbound = { id: string; mode: string; object: string; status: string; name: string; code: string; type: string; amount?: number | undefined; currency?: string | undefined; percentage?: number | undefined; expiry_date?: string | undefined; max_redemptions?: number | undefined; duration?: string | undefined; duration_in_months?: number | undefined; applies_to_products?: Array | undefined; redeem_count?: number | undefined; }; /** @internal */ export const DiscountEntity$outboundSchema: z.ZodType< DiscountEntity$Outbound, z.ZodTypeDef, DiscountEntity > = z.object({ id: z.string(), mode: EnvironmentMode$outboundSchema, object: z.string(), status: DiscountEntityStatus$outboundSchema, name: z.string(), code: z.string(), type: Type$outboundSchema, amount: z.number().optional(), currency: z.string().optional(), percentage: z.number().optional(), expiryDate: z.date().transform(v => v.toISOString()).optional(), maxRedemptions: z.number().optional(), duration: Duration$outboundSchema.optional(), durationInMonths: z.number().optional(), appliesToProducts: z.array(z.string()).optional(), redeemCount: z.number().optional(), }).transform((v) => { return remap$(v, { expiryDate: "expiry_date", maxRedemptions: "max_redemptions", durationInMonths: "duration_in_months", appliesToProducts: "applies_to_products", redeemCount: "redeem_count", }); }); export function discountEntityToJSON(discountEntity: DiscountEntity): string { return JSON.stringify(DiscountEntity$outboundSchema.parse(discountEntity)); } export function discountEntityFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => DiscountEntity$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'DiscountEntity' from JSON`, ); }