import {z} from 'zod' export type MilestoneType = number; export type CreateJourneyMilestoneTemplateRequest = {name?: string | undefined, type?: MilestoneType | undefined, orderIndex?: (number | unknown) | undefined, description?: (string | null) | undefined, estimatedDurationMinutes?: (number | unknown | null) | undefined}; export type CreateDefaultServiceInput = {serviceCatalogItemId?: (string | null) | undefined, inventoryItemId?: (string | null) | undefined, defaultQuantity?: (number | unknown) | undefined, displayOrder?: (number | unknown) | undefined}; export type CreateAppointmentTypeDto = {name?: string | undefined, description?: (string | null) | undefined, durationMinutes?: (number | unknown) | undefined, bufferBeforeMinutes?: (number | unknown) | undefined, bufferAfterMinutes?: (number | unknown) | undefined, color?: (string | null) | undefined, requiresSurgeryRoom?: boolean | undefined, isGroupVisit?: boolean | undefined, isCompassionCare?: boolean | undefined, allowOnlineBooking?: boolean | undefined, excludeFromAutomatedForms?: boolean | undefined, sortOrder?: (number | unknown) | undefined, acuity?: (number | unknown | null) | undefined, defaultFlowId?: (string | null) | undefined, examTemplateId?: (string | null) | undefined, noteFormat?: (string | null) | undefined, autoGenerateSoap?: boolean | undefined, autoGenerateDischarge?: boolean | undefined, locationIds?: (Array | null) | undefined, journeyTemplates?: (Array | null) | undefined, defaultServices?: (Array | null) | undefined}; export type CreateApiAppointmentTypesArgs = {body: CreateAppointmentTypeDto}; export type CreateApiAppointmentTypesOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const milestoneType = z.number().int(); export const journeyMilestoneTemplateDto = z.object({id: z.string().optional(), appointmentTypeId: z.string().optional(), name: z.string().optional(), type: milestoneType.optional(), orderIndex: z.union([z.number().int(), z.string()]).optional(), description: z.string().nullable().optional(), estimatedDurationMinutes: z.union([z.number().int(), z.string()]).nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const appointmentTypeDefaultServiceDto = z.object({id: z.string().optional(), appointmentTypeId: z.string().optional(), serviceCatalogItemId: z.string().nullable().optional(), inventoryItemId: z.string().nullable().optional(), name: z.string().optional(), code: z.string().nullable().optional(), serviceType: z.string().optional(), unitPrice: z.union([z.number(), z.string()]).optional(), defaultQuantity: z.union([z.number(), z.string()]).optional(), displayOrder: z.union([z.number().int(), z.string()]).optional(), isActive: z.boolean().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const appointmentTypeDto = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().nullable().optional(), durationMinutes: z.union([z.number().int(), z.string()]).optional(), bufferBeforeMinutes: z.union([z.number().int(), z.string()]).optional(), bufferAfterMinutes: z.union([z.number().int(), z.string()]).optional(), color: z.string().nullable().optional(), isActive: z.boolean().optional(), requiresSurgeryRoom: z.boolean().optional(), isGroupVisit: z.boolean().optional(), isCompassionCare: z.boolean().optional(), allowOnlineBooking: z.boolean().optional(), excludeFromAutomatedForms: z.boolean().optional(), sortOrder: z.union([z.number().int(), z.string()]).optional(), acuity: z.union([z.number().int(), z.string()]).nullable().optional(), defaultFlowId: z.string().nullable().optional(), examTemplateId: z.string().nullable().optional(), noteFormat: z.string().nullable().optional(), autoGenerateSoap: z.boolean().optional(), autoGenerateDischarge: z.boolean().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), locationIds: z.array(z.string()).optional(), journeyTemplates: z.array(journeyMilestoneTemplateDto).optional(), defaultServices: z.array(appointmentTypeDefaultServiceDto).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 /appointment-types */ export const createApiAppointmentTypes = async (args: CreateApiAppointmentTypesArgs, options?: CreateApiAppointmentTypesOptions) => { 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(/\/+$/, '')}/appointment-types${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(appointmentTypeDto, await res.json()) };