import {z} from 'zod' export type PatchApiAppointmentsV1AppointmentIdRescheduleArgs = {auth: string, appointment_id: string, body: {start_time: number, end_time: number, partner_appointment_id?: string | undefined}}; export type PatchApiAppointmentsV1AppointmentIdRescheduleOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiAppointmentsV1AppointmentIdRescheduleResponse = z.object({appointment_id: z.string().optional(), patient_id: z.string().optional(), doctor_id: z.string().nullable().optional(), clinic_id: z.string().optional(), status: z.string().optional(), mode: z.string().optional(), start_time: z.number().int().optional(), end_time: z.number().int().optional(), created_at: z.number().int().optional(), prev_aids: z.array(z.string()).optional(), next_aid: 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 }; /** * Reschedule Appointment * * PATCH /appointments/v1/{appointment_id}/reschedule */ export const patchApiAppointmentsV1AppointmentIdReschedule = async (args: PatchApiAppointmentsV1AppointmentIdRescheduleArgs, options?: PatchApiAppointmentsV1AppointmentIdRescheduleOptions) => { const {baseUrl = "https://api.eka.care", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.auth != null) headers.set("auth", String(args.auth)) const url = `${baseUrl.replace(/\/+$/, '')}/appointments/v1/${encodeURIComponent(String(args.appointment_id))}/reschedule${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiAppointmentsV1AppointmentIdRescheduleResponse, await res.json()) };