import {z} from 'zod' export type GetApiAvailableSlotsArgs = {'Nex-Api-Version': string, subdomain: string, start_date: string, days: number, appointment_type_id?: number | undefined, working_hour_label_id?: number | undefined, working_hour_source?: ('manual' | 'synced') | undefined, slot_length?: number | undefined, slot_interval?: number | undefined, overlapping_operatory_slots?: boolean | undefined, appointments_per_timeslot?: number | undefined, 'lids[]': Array, 'pids[]'?: Array | undefined, 'operatory_ids[]'?: Array | undefined}; export type GetApiAvailableSlotsOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const aPIV20240412EntitiesAvailableSlot = z.object({time: z.string().optional(), end_time: z.string().optional(), operatory_id: z.number().int().optional(), provider_id: z.number().int().optional(), working_hour_label_id: z.number().int().nullable().optional()}); export const aPIV20240412EntitiesAvailableSlotResponse = z.object({lid: z.number().int().optional(), pid: z.number().int().nullable().optional(), operatory_id: z.number().int().nullable().optional(), slots: z.array(aPIV20240412EntitiesAvailableSlot).optional(), next_available_date: z.string().nullable().optional()}); export const aPIV20240412EntitiesAvailableSlotResponseCollectionResponse = z.object({code: z.boolean().optional(), description: z.string().optional(), error: z.array(z.string()).optional(), data: z.array(aPIV20240412EntitiesAvailableSlotResponse).optional(), count: z.number().int().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 }; /** * View available slots * * GET /available_slots */ export const getApiAvailableSlots = async (args: GetApiAvailableSlotsArgs, options?: GetApiAvailableSlotsOptions) => { const {baseUrl = "https://nexhealth.info", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Nex-Api-Version'] != null) headers.set("Nex-Api-Version", String(args['Nex-Api-Version'])) if (args.subdomain != null) query.append("subdomain", String(args.subdomain)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.days != null) query.append("days", String(args.days)) if (args.appointment_type_id != null) query.append("appointment_type_id", String(args.appointment_type_id)) if (args.working_hour_label_id != null) query.append("working_hour_label_id", String(args.working_hour_label_id)) if (args.working_hour_source != null) query.append("working_hour_source", String(args.working_hour_source)) if (args.slot_length != null) query.append("slot_length", String(args.slot_length)) if (args.slot_interval != null) query.append("slot_interval", String(args.slot_interval)) if (args.overlapping_operatory_slots != null) query.append("overlapping_operatory_slots", String(args.overlapping_operatory_slots)) if (args.appointments_per_timeslot != null) query.append("appointments_per_timeslot", String(args.appointments_per_timeslot)) for (const item of args['lids[]'] ?? []) query.append("lids[]", String(item)) for (const item of args['pids[]'] ?? []) query.append("pids[]", String(item)) for (const item of args['operatory_ids[]'] ?? []) query.append("operatory_ids[]", String(item)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/available_slots${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(aPIV20240412EntitiesAvailableSlotResponseCollectionResponse, await res.json()) };