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 MachinePaymentResponse = {MachineID?: number | undefined, PaymentMethodID?: number | undefined, ConvenienceFeePercentageBit?: (boolean | null) | undefined, ConvenienceFeeValue?: number | undefined, LastUpdated?: string | undefined, ExternalPaymentProviderUsername?: (string | null) | undefined, ExternalPaymentProviderPassword?: (string | null) | undefined, ExternalPaymentProviderTerminalID?: (string | null) | undefined, ExternalPaymentProviderLocationIdentifier?: (string | null) | undefined, PaymentMethodWorkingDays?: (Array | null) | undefined, PaymentMethodCustomData?: (string | null) | undefined, ConvenienceFeeBackupValue?: number | undefined, PaymentMethodQRString?: (string | null) | undefined}; export type UpdateApiV1MachinesMachineIDPaymentMethodsArgs = {MachineID: number, body: Array}; export type UpdateApiV1MachinesMachineIDPaymentMethodsOptions = {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 machinePaymentResponse = z.object({MachineID: z.number().int().optional(), PaymentMethodID: z.number().int().optional(), ConvenienceFeePercentageBit: z.boolean().nullable().optional(), ConvenienceFeeValue: z.number().optional(), LastUpdated: z.string().optional(), ExternalPaymentProviderUsername: z.string().nullable().optional(), ExternalPaymentProviderPassword: z.string().nullable().optional(), ExternalPaymentProviderTerminalID: z.string().nullable().optional(), ExternalPaymentProviderLocationIdentifier: z.string().nullable().optional(), PaymentMethodWorkingDays: z.array(workDay).nullable().optional(), PaymentMethodCustomData: z.string().nullable().optional(), ConvenienceFeeBackupValue: z.number().optional(), PaymentMethodQRString: z.string().nullable().optional()}); export const updateApiV1MachinesMachineIDPaymentMethodsResponse = z.array(machinePaymentResponse); 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 }; /** * Update Payment Methods for Machine * * PUT /v1/machines/{MachineID}/paymentMethods */ export const updateApiV1MachinesMachineIDPaymentMethods = async (args: UpdateApiV1MachinesMachineIDPaymentMethodsArgs, options?: UpdateApiV1MachinesMachineIDPaymentMethodsOptions) => { 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/machines/${encodeURIComponent(String(args.MachineID))}/paymentMethods${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV1MachinesMachineIDPaymentMethodsResponse, await res.json()) };