/* * 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"; import { MetadataOutputType, MetadataOutputType$inboundSchema, MetadataOutputType$Outbound, MetadataOutputType$outboundSchema, } from "./metadataoutputtype.js"; export type DiscountFixedRepeatDurationBase = { 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 }; /** * Creation timestamp of the object. */ createdAt: Date; /** * Last modification timestamp of the object. */ modifiedAt: Date | null; /** * The ID of the object. */ id: string; metadata: { [k: string]: MetadataOutputType }; /** * Name of the discount. Will be displayed to the customer when the discount is applied. */ name: string; /** * Code customers can use to apply the discount during checkout. */ code: string | null; /** * Timestamp after which the discount is redeemable. */ startsAt: Date | null; /** * Timestamp after which the discount is no longer redeemable. */ endsAt: Date | null; /** * Maximum number of times the discount can be redeemed. */ maxRedemptions: number | null; /** * Number of times the discount has been redeemed. */ redemptionsCount: number; /** * The organization ID. */ organizationId: string; }; /** @internal */ export const DiscountFixedRepeatDurationBase$inboundSchema: z.ZodMiniType< DiscountFixedRepeatDurationBase, 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()), created_at: z.pipe( z.iso.datetime({ offset: true }), z.transform(v => new Date(v)), ), modified_at: z.nullable( z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))), ), id: z.string(), metadata: z.record(z.string(), MetadataOutputType$inboundSchema), name: z.string(), code: z.nullable(z.string()), starts_at: z.nullable( z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))), ), ends_at: z.nullable( z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))), ), max_redemptions: z.nullable(z.int()), redemptions_count: z.int(), organization_id: z.string(), }), z.transform((v) => { return remap$(v, { "duration_in_months": "durationInMonths", "created_at": "createdAt", "modified_at": "modifiedAt", "starts_at": "startsAt", "ends_at": "endsAt", "max_redemptions": "maxRedemptions", "redemptions_count": "redemptionsCount", "organization_id": "organizationId", }); }), ); /** @internal */ export type DiscountFixedRepeatDurationBase$Outbound = { duration: string; duration_in_months: number; type: string; amount: number; currency: string; amounts: { [k: string]: number }; created_at: string; modified_at: string | null; id: string; metadata: { [k: string]: MetadataOutputType$Outbound }; name: string; code: string | null; starts_at: string | null; ends_at: string | null; max_redemptions: number | null; redemptions_count: number; organization_id: string; }; /** @internal */ export const DiscountFixedRepeatDurationBase$outboundSchema: z.ZodMiniType< DiscountFixedRepeatDurationBase$Outbound, DiscountFixedRepeatDurationBase > = 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()), createdAt: z.pipe(z.date(), z.transform(v => v.toISOString())), modifiedAt: z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))), id: z.string(), metadata: z.record(z.string(), MetadataOutputType$outboundSchema), name: z.string(), code: z.nullable(z.string()), startsAt: z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))), endsAt: z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))), maxRedemptions: z.nullable(z.int()), redemptionsCount: z.int(), organizationId: z.string(), }), z.transform((v) => { return remap$(v, { durationInMonths: "duration_in_months", createdAt: "created_at", modifiedAt: "modified_at", startsAt: "starts_at", endsAt: "ends_at", maxRedemptions: "max_redemptions", redemptionsCount: "redemptions_count", organizationId: "organization_id", }); }), ); export function discountFixedRepeatDurationBaseToJSON( discountFixedRepeatDurationBase: DiscountFixedRepeatDurationBase, ): string { return JSON.stringify( DiscountFixedRepeatDurationBase$outboundSchema.parse( discountFixedRepeatDurationBase, ), ); } export function discountFixedRepeatDurationBaseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => DiscountFixedRepeatDurationBase$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'DiscountFixedRepeatDurationBase' from JSON`, ); }