import {z} from 'zod' export type WorkDay = {name?: (string | null) | undefined, week_day?: (number | null) | undefined, start_time?: (unknown | null) | undefined, end_time?: (unknown | null) | undefined, work_hour_lut_id?: (number | null) | undefined}; export type ActorPaymentResponse = {ActorID?: number | undefined, PaymentMethodID?: number | undefined, ExtraChargePercentageBit?: (boolean | null) | undefined, ExtraChargeValue?: number | undefined, LastUpdated?: (string | null) | undefined, ExternalPaymentProviderURL?: (string | null) | undefined, ExternalPaymentProviderID?: (number | null) | undefined, ExternalPaymentProviderModeID?: (number | null) | undefined, ExternalPaymentProviderUsername?: (string | null) | undefined, ExternalPaymentProviderPassword?: (string | null) | undefined, ExternalPaymentProviderMerchantID?: (string | null) | undefined, ExternalPaymentProviderKey?: (string | null) | undefined, ExternalPaymentProviderAppID?: (string | null) | undefined, ExternalPaymentProviderCertificatePath?: (string | null) | undefined, ExternalPaymentProviderCertificatePassword?: (string | null) | undefined, ExternalPaymentProviderApiKey?: (string | null) | undefined, ExternalPaymentProviderLocationIdentifier?: (string | null) | undefined, PaymentMethodWorkingDays?: (Array | null) | undefined, PaymentMethodCustomData?: (string | null) | undefined, ExtraChargeBackupValue?: number | undefined, ChargeMachineID?: (number | null) | undefined}; export type CreateApiV1ActorsActorIDPaymentMethodsArgs = {ActorID: number, body: Array}; export type CreateApiV1ActorsActorIDPaymentMethodsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const workDay = z.object({name: z.string().nullable().optional(), week_day: z.number().int().nullable().optional(), start_time: z.string().nullable().optional(), end_time: z.string().nullable().optional(), work_hour_lut_id: z.number().int().nullable().optional()}); export const actorPaymentResponse = z.object({ActorID: z.number().int().optional(), PaymentMethodID: z.number().int().optional(), ExtraChargePercentageBit: z.boolean().nullable().optional(), ExtraChargeValue: z.number().optional(), LastUpdated: z.string().nullable().optional(), ExternalPaymentProviderURL: z.string().nullable().optional(), ExternalPaymentProviderID: z.number().int().nullable().optional(), ExternalPaymentProviderModeID: z.number().int().nullable().optional(), ExternalPaymentProviderUsername: z.string().nullable().optional(), ExternalPaymentProviderPassword: z.string().nullable().optional(), ExternalPaymentProviderMerchantID: z.string().nullable().optional(), ExternalPaymentProviderKey: z.string().nullable().optional(), ExternalPaymentProviderAppID: z.string().nullable().optional(), ExternalPaymentProviderCertificatePath: z.string().nullable().optional(), ExternalPaymentProviderCertificatePassword: z.string().nullable().optional(), ExternalPaymentProviderApiKey: z.string().nullable().optional(), ExternalPaymentProviderLocationIdentifier: z.string().nullable().optional(), PaymentMethodWorkingDays: z.array(workDay).nullable().optional(), PaymentMethodCustomData: z.string().nullable().optional(), ExtraChargeBackupValue: z.number().optional(), ChargeMachineID: z.number().int().nullable().optional()}); export const createApiV1ActorsActorIDPaymentMethodsResponse = z.array(actorPaymentResponse); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create Actor's Payment Methods * * POST /v1/actors/{ActorID}/paymentMethods */ export const createApiV1ActorsActorIDPaymentMethods = async (args: CreateApiV1ActorsActorIDPaymentMethodsArgs, options?: CreateApiV1ActorsActorIDPaymentMethodsOptions) => { const {baseUrl = "https://example.com:443", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/actors/${encodeURIComponent(String(args.ActorID))}/paymentMethods${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV1ActorsActorIDPaymentMethodsResponse, await res.json()) };