/* * 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 { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { CouponDurationType, CouponDurationType$inboundSchema, CouponDurationType$outboundSchema, } from "./coupondurationtype.js"; import { DiscountType, DiscountType$inboundSchema, DiscountType$outboundSchema, } from "./discounttype.js"; export type CreateDiscountRequestEntity = { /** * The name of the discount. */ name: string; /** * Optional discount code. If left empty, a code will be generated. */ code?: string | undefined; /** * The type of the discount, either "percentage" or "fixed". */ type: DiscountType; /** * The fixed value for the discount. Only applicable if the type is "fixed". */ amount?: number | undefined; /** * The currency of the discount. Only required if type is "fixed". */ currency?: string | undefined; /** * The percentage value for the discount. Only applicable if the type is "percentage". */ percentage?: number | undefined; /** * The expiry date of the discount. */ expiryDate?: Date | undefined; /** * The maximum number of redemptions for the discount. */ maxRedemptions?: number | undefined; /** * The duration type for the discount. */ duration: CouponDurationType; /** * 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; }; /** @internal */ export const CreateDiscountRequestEntity$inboundSchema: z.ZodType< CreateDiscountRequestEntity, z.ZodTypeDef, unknown > = z.object({ name: z.string(), code: z.string().optional(), type: DiscountType$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: CouponDurationType$inboundSchema, duration_in_months: z.number().optional(), applies_to_products: z.array(z.string()), }).transform((v) => { return remap$(v, { "expiry_date": "expiryDate", "max_redemptions": "maxRedemptions", "duration_in_months": "durationInMonths", "applies_to_products": "appliesToProducts", }); }); /** @internal */ export type CreateDiscountRequestEntity$Outbound = { name: string; code?: string | undefined; type: string; amount?: number | undefined; currency?: string | undefined; percentage?: number | undefined; expiry_date?: string | undefined; max_redemptions?: number | undefined; duration: string; duration_in_months?: number | undefined; applies_to_products: Array; }; /** @internal */ export const CreateDiscountRequestEntity$outboundSchema: z.ZodType< CreateDiscountRequestEntity$Outbound, z.ZodTypeDef, CreateDiscountRequestEntity > = z.object({ name: z.string(), code: z.string().optional(), type: DiscountType$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: CouponDurationType$outboundSchema, durationInMonths: z.number().optional(), appliesToProducts: z.array(z.string()), }).transform((v) => { return remap$(v, { expiryDate: "expiry_date", maxRedemptions: "max_redemptions", durationInMonths: "duration_in_months", appliesToProducts: "applies_to_products", }); }); export function createDiscountRequestEntityToJSON( createDiscountRequestEntity: CreateDiscountRequestEntity, ): string { return JSON.stringify( CreateDiscountRequestEntity$outboundSchema.parse( createDiscountRequestEntity, ), ); } export function createDiscountRequestEntityFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateDiscountRequestEntity$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateDiscountRequestEntity' from JSON`, ); }