import {z} from 'zod' export type UpdateClientDto = {registrationPending?: (boolean | null) | undefined, email?: (string | null) | undefined, firstName?: (string | null) | undefined, lastName?: (string | null) | undefined, phoneNumber?: (string | null) | undefined, address?: (string | null) | undefined, addressLine2?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, zipCode?: (string | null) | undefined, countryCode?: (string | null) | undefined, dateOfBirth?: (string | null) | undefined, clearDateOfBirth?: boolean | undefined, accountStatus?: (string | null) | undefined, preferredContactMethod?: (string | null) | undefined, allowAppointmentReminders?: (boolean | null) | undefined, allowEmailMarketing?: (boolean | null) | undefined, allowPhoneCalls?: (boolean | null) | undefined, allowSmsMarketing?: (boolean | null) | undefined, communicationNotes?: (string | null) | undefined, emergencyContactName?: (string | null) | undefined, emergencyContactPhone?: (string | null) | undefined, emergencyContactEmail?: (string | null) | undefined, emergencyContactRelationship?: (string | null) | undefined, secondaryEmergencyContactName?: (string | null) | undefined, secondaryEmergencyContactPhone?: (string | null) | undefined, secondaryEmergencyContactEmail?: (string | null) | undefined, secondaryEmergencyContactRelationship?: (string | null) | undefined, preferredLanguage?: (string | null) | undefined, referralSource?: (string | null) | undefined}; export type UpdateApiClientsIdArgs = {id: string, body: UpdateClientDto}; export type UpdateApiClientsIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const accountStatus = z.number().int(); export const emergencyContactDto = z.object({name: z.string().nullable().optional(), phone: z.string().nullable().optional(), email: z.string().nullable().optional(), relationship: z.string().nullable().optional()}); export const secondaryEmergencyContactDto = z.object({name: z.string().nullable().optional(), phone: z.string().nullable().optional(), email: z.string().nullable().optional(), relationship: z.string().nullable().optional()}); export const contactMethod = z.number().int(); export const communicationPreferencesDto = z.object({preferredMethod: contactMethod.optional(), allowAppointmentReminders: z.boolean().optional(), allowEmailMarketing: z.boolean().optional(), allowPhoneCalls: z.boolean().optional(), allowSmsMarketing: z.boolean().optional(), notes: z.string().nullable().optional()}); export const clientResponseDto = z.object({id: z.string().optional(), email: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional(), firstName: z.string().optional(), lastName: z.string().optional(), address: z.string().nullable().optional(), addressLine2: z.string().nullable().optional(), city: z.string().nullable().optional(), state: z.string().nullable().optional(), zipCode: z.string().nullable().optional(), countryCode: z.string().nullable().optional(), dateOfBirth: z.string().nullable().optional(), accountStatus: accountStatus.optional(), emergencyContact: emergencyContactDto.optional(), secondaryEmergencyContact: secondaryEmergencyContactDto.nullable().optional(), communicationPreferences: communicationPreferencesDto.optional(), emailSuppressedAt: z.string().nullable().optional(), emailSuppressionReason: z.string().nullable().optional(), preferredLanguage: z.string().nullable().optional(), referralSource: z.string().nullable().optional(), createdVia: z.string().nullable().optional(), registrationPending: z.boolean().optional(), allowHouseAccount: z.boolean().optional(), paymentTermsDays: z.union([z.number().int(), z.string()]).nullable().optional(), createdAt: z.string().optional(), updatedAt: 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 }; /** * PUT /Clients/{id} */ export const updateApiClientsId = async (args: UpdateApiClientsIdArgs, options?: UpdateApiClientsIdOptions) => { 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(/\/+$/, '')}/Clients/${encodeURIComponent(String(args.id))}${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(clientResponseDto, await res.json()) };