import {z} from 'zod' export type CreateGroupTreatmentRequest = {inventoryItemId?: (string | null) | undefined, serviceCatalogItemId?: (string | null) | undefined, quantityUsed?: (number | unknown | null) | undefined, dose?: (string | null) | undefined, route?: (string | null) | undefined, frequency?: (string | null) | undefined, duration?: (string | null) | undefined, numberTreated?: (number | unknown | null) | undefined, cohortLabel?: (string | null) | undefined, meatWithdrawalEndDate?: (string | null) | undefined, milkWithdrawalEndDate?: (string | null) | undefined, notes?: (string | null) | undefined}; export type CreateApiGroupVisitsAppointmentIdTreatmentsArgs = {appointmentId: string, body: CreateGroupTreatmentRequest}; export type CreateApiGroupVisitsAppointmentIdTreatmentsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const groupTreatmentDto = z.object({id: z.string().optional(), productName: z.string().optional(), dose: z.string().nullable().optional(), route: z.string().nullable().optional(), frequency: z.string().nullable().optional(), duration: z.string().nullable().optional(), numberTreated: z.union([z.number().int(), z.string()]).nullable().optional(), cohortLabel: z.string().nullable().optional(), inventoryItemId: z.string().nullable().optional(), serviceCatalogItemId: z.string().nullable().optional(), quantityUsed: z.union([z.number(), z.string()]).nullable().optional(), inventoryTransactionId: z.string().nullable().optional(), meatWithdrawalEndDate: z.string().nullable().optional(), milkWithdrawalEndDate: z.string().nullable().optional(), notes: z.string().nullable().optional(), createdById: z.string().optional(), createdAt: 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 }; /** * POST /GroupVisits/{appointmentId}/treatments */ export const createApiGroupVisitsAppointmentIdTreatments = async (args: CreateApiGroupVisitsAppointmentIdTreatmentsArgs, options?: CreateApiGroupVisitsAppointmentIdTreatmentsOptions) => { 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(/\/+$/, '')}/GroupVisits/${encodeURIComponent(String(args.appointmentId))}/treatments${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(groupTreatmentDto, await res.json()) };