import {z} from 'zod' export type PaymentMethodNoticeDto = {surfaceKey?: string | undefined, text?: string | undefined, severity?: string | undefined}; export type FinancialSettingsDto = {stateTaxRate?: (number | unknown) | undefined, countyTaxRate?: (number | unknown) | undefined, cityTaxRate?: (number | unknown) | undefined, quickAddServiceIds?: (Array | null) | undefined, xplorPayEnabled?: boolean | undefined, xplorPayTestMode?: boolean | undefined, xplorPayCredentialsConfigured?: boolean | undefined, xplorPayTerminalApiKey?: (string | null) | undefined, xplorPayPayLinkApiKey?: (string | null) | undefined, markAsPaidTypes?: (Array | null) | undefined, defaultPaymentTermsDays?: (number | unknown) | undefined, passProcessingFeesToClient?: boolean | undefined, depositAccount?: (string | null) | undefined, accountingMode?: (string | null) | undefined, taxMode?: (string | null) | undefined, vatStandardRate?: (number | unknown) | undefined, vatReducedRate?: (number | unknown) | undefined, discountStackingMode?: string | undefined, autoCategoryGroups?: boolean | undefined, paymentMethodNotices?: (Array | null) | undefined}; export type PatchApiClinicConfigFinancialArgs = {body: FinancialSettingsDto}; export type PatchApiClinicConfigFinancialOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const paymentMethodNoticeDto = z.object({surfaceKey: z.string().optional(), text: z.string().optional(), severity: z.string().optional()}); export const financialSettingsDto = z.object({stateTaxRate: z.union([z.number(), z.string()]).optional(), countyTaxRate: z.union([z.number(), z.string()]).optional(), cityTaxRate: z.union([z.number(), z.string()]).optional(), quickAddServiceIds: z.array(z.string()).nullable().optional(), xplorPayEnabled: z.boolean().optional(), xplorPayTestMode: z.boolean().optional(), xplorPayCredentialsConfigured: z.boolean().optional(), xplorPayTerminalApiKey: z.string().nullable().optional(), xplorPayPayLinkApiKey: z.string().nullable().optional(), markAsPaidTypes: z.array(z.string()).nullable().optional(), defaultPaymentTermsDays: z.union([z.number().int(), z.string()]).optional(), passProcessingFeesToClient: z.boolean().optional(), depositAccount: z.string().nullable().optional(), accountingMode: z.string().nullable().optional(), taxMode: z.string().nullable().optional(), vatStandardRate: z.union([z.number(), z.string()]).optional(), vatReducedRate: z.union([z.number(), z.string()]).optional(), discountStackingMode: z.string().optional(), autoCategoryGroups: z.boolean().optional(), paymentMethodNotices: z.array(paymentMethodNoticeDto).nullable().optional()}); 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 }; /** * PATCH /clinic-config/financial - Update financial settings * * PATCH /clinic-config/financial */ export const patchApiClinicConfigFinancial = async (args: PatchApiClinicConfigFinancialArgs, options?: PatchApiClinicConfigFinancialOptions) => { const {baseUrl = "https://api.clinicos.vet/backend/business", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/clinic-config/financial${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(financialSettingsDto, await res.json()) };