import {z} from 'zod' export type LocationHoursEntryDto = {dayOfWeek?: (number | unknown) | undefined, openTime?: string | undefined, closeTime?: string | undefined, isOpen?: boolean | undefined}; export type TravelAddressConfigDto = {address?: (string | null) | undefined, placeId?: (string | null) | undefined, latitude?: (number | unknown | null) | undefined, longitude?: (number | unknown | null) | undefined}; export type TravelFeeTierDto = {maxDistanceMiles?: (number | unknown) | undefined, feeAmount?: (number | unknown) | undefined}; export type TravelFeeConfigDto = {calculationMethod?: string | undefined, baseFee?: (number | unknown) | undefined, perMileRate?: (number | unknown) | undefined, flatRateAmount?: (number | unknown) | undefined, tiers?: Array | undefined}; export type TravelSettingsDto = {travelAppointmentsEnabled?: boolean | undefined, personalVehicleEnabled?: boolean | undefined, personalVehicleLocationId?: (string | null) | undefined, defaultStartingAddress?: TravelAddressConfigDto | undefined, feeConfig?: TravelFeeConfigDto | undefined, defaultRoundTrip?: boolean | undefined, maxDistanceMiles?: (number | unknown | null) | undefined}; export type SchedulingPreferencesDto = {roomManagementEnabled?: boolean | undefined, unassignedLocationId?: (string | null) | undefined, showRescheduledMarkers?: (boolean | null) | undefined}; export type MetricsSettingsDto = {compensationThresholdPercent?: (number | unknown) | undefined}; export type UpdateClinicSettingsRequest = {companyName?: (string | null) | undefined, clinicAddress?: (string | null) | undefined, clinicPhone?: (string | null) | undefined, clinicEmail?: (string | null) | undefined, clinicFax?: (string | null) | undefined, clinicAboutNotes?: (string | null) | undefined, defaultAppointmentDurationMinutes?: (number | unknown | null) | undefined, schedulingPolicy?: (string | null) | undefined, timezone?: (string | null) | undefined, defaultWeeklyHours?: (Array | null) | undefined, travel?: (TravelSettingsDto | null) | undefined, schedulingPreferences?: (SchedulingPreferencesDto | null) | undefined, metrics?: (MetricsSettingsDto | null) | undefined, widgetAllowedDomains?: (Array | null) | undefined}; export type PatchApiClinicSettingsArgs = {body: UpdateClinicSettingsRequest}; export type PatchApiClinicSettingsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const locationHoursEntryDto = z.object({dayOfWeek: z.union([z.number().int(), z.string()]).optional(), openTime: z.string().optional(), closeTime: z.string().optional(), isOpen: z.boolean().optional()}); export const travelAddressConfigDto = z.object({address: z.string().nullable().optional(), placeId: z.string().nullable().optional(), latitude: z.union([z.number(), z.string()]).nullable().optional(), longitude: z.union([z.number(), z.string()]).nullable().optional()}); export const travelFeeTierDto = z.object({maxDistanceMiles: z.union([z.number().int(), z.string()]).optional(), feeAmount: z.union([z.number(), z.string()]).optional()}); export const travelFeeConfigDto = z.object({calculationMethod: z.string().optional(), baseFee: z.union([z.number(), z.string()]).optional(), perMileRate: z.union([z.number(), z.string()]).optional(), flatRateAmount: z.union([z.number(), z.string()]).optional(), tiers: z.array(travelFeeTierDto).optional()}); export const travelSettingsDto = z.object({travelAppointmentsEnabled: z.boolean().optional(), personalVehicleEnabled: z.boolean().optional(), personalVehicleLocationId: z.string().nullable().optional(), defaultStartingAddress: travelAddressConfigDto.optional(), feeConfig: travelFeeConfigDto.optional(), defaultRoundTrip: z.boolean().optional(), maxDistanceMiles: z.union([z.number().int(), z.string()]).nullable().optional()}); export const schedulingPreferencesDto = z.object({roomManagementEnabled: z.boolean().optional(), unassignedLocationId: z.string().nullable().optional(), showRescheduledMarkers: z.boolean().nullable().optional()}); export const metricsSettingsDto = z.object({compensationThresholdPercent: z.union([z.number(), z.string()]).optional()}); export const clinicSettingsDto = z.object({companyId: z.string().optional(), companyName: z.string().optional(), clinicAddress: z.string().nullable().optional(), clinicPhone: z.string().nullable().optional(), clinicEmail: z.string().nullable().optional(), clinicFax: z.string().nullable().optional(), clinicAboutNotes: z.string().nullable().optional(), defaultAppointmentDurationMinutes: z.union([z.number().int(), z.string()]).optional(), schedulingPolicy: z.string().optional(), timezone: z.string().optional(), timezoneConfigured: z.boolean().optional(), defaultWeeklyHours: z.array(locationHoursEntryDto).nullable().optional(), travel: travelSettingsDto.nullable().optional(), schedulingPreferences: schedulingPreferencesDto.nullable().optional(), metrics: metricsSettingsDto.nullable().optional(), billingStatus: z.string().nullable().optional(), widgetAllowedDomains: z.array(z.string()).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-settings */ export const patchApiClinicSettings = async (args: PatchApiClinicSettingsArgs, options?: PatchApiClinicSettingsOptions) => { 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-settings${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(clinicSettingsDto, await res.json()) };