import {z} from 'zod' export type UpdateSurgicalTimelineEventRequest = {title?: (string | null) | undefined, details?: (string | null) | undefined, isPinned?: (boolean | null) | undefined, occurredAt?: (string | null) | undefined, amendmentReason?: (string | null) | undefined}; export type UpdateApiSurgicalRecordsIdEventsEventIdArgs = {id: string, eventId: string, body: UpdateSurgicalTimelineEventRequest}; export type UpdateApiSurgicalRecordsIdEventsEventIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const surgicalTimelineEventAmendmentDto = z.object({id: z.string().optional(), originalOccurredAt: z.string().optional(), amendedOccurredAt: z.string().optional(), reason: z.string().nullable().optional(), amendedById: z.string().nullable().optional(), amendedByName: z.string().nullable().optional(), createdAt: z.string().optional()}); export const surgicalTimelineEventDto = z.object({id: z.string().optional(), surgicalRecordId: z.string().optional(), title: z.string().optional(), details: z.string().nullable().optional(), type: z.string().optional(), color: z.string().nullable().optional(), isPinned: z.boolean().optional(), occurredAt: z.string().optional(), sortOrder: z.union([z.number().int(), z.string()]).optional(), createdByAi: z.boolean().optional(), milestoneKind: z.string().nullable().optional(), inventoryItemId: z.string().nullable().optional(), doseAmount: z.union([z.number(), z.string()]).nullable().optional(), doseUnit: z.string().nullable().optional(), route: z.string().nullable().optional(), createdAt: z.string().optional(), amendments: z.array(surgicalTimelineEventAmendmentDto).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 /SurgicalRecords/{id}/events/{eventId} */ export const updateApiSurgicalRecordsIdEventsEventId = async (args: UpdateApiSurgicalRecordsIdEventsEventIdArgs, options?: UpdateApiSurgicalRecordsIdEventsEventIdOptions) => { 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(/\/+$/, '')}/SurgicalRecords/${encodeURIComponent(String(args.id))}/events/${encodeURIComponent(String(args.eventId))}${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(surgicalTimelineEventDto, await res.json()) };