import {z} from 'zod' export type CreateSurgicalTimelineEventRequest = {title: string, details?: (string | null) | undefined, type: string, color?: (string | null) | undefined, isPinned?: boolean | undefined, occurredAt?: (string | null) | undefined, createdByAi?: boolean | undefined, milestoneKind?: (string | null) | undefined, implicit?: boolean | undefined, inventoryItemId?: (string | null) | undefined, doseAmount?: (number | unknown | null) | undefined, doseUnit?: (string | null) | undefined, route?: (string | null) | undefined}; export type CreateApiSurgicalRecordsIdEventsArgs = {id: string, body: CreateSurgicalTimelineEventRequest}; export type CreateApiSurgicalRecordsIdEventsOptions = {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 }; /** * POST /SurgicalRecords/{id}/events */ export const createApiSurgicalRecordsIdEvents = async (args: CreateApiSurgicalRecordsIdEventsArgs, options?: CreateApiSurgicalRecordsIdEventsOptions) => { 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${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(surgicalTimelineEventDto, await res.json()) };