import {z} from 'zod' export type GetApiBusinessSchedulesAppointmentsArgs = {SiteId: number, appointmentId: Array}; export type GetApiBusinessSchedulesAppointmentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mindbodyContractSchedulingModelsCommonDateTimeRange = z.object({Start: z.string().optional(), End: z.string().optional()}); export const mindbodyContractSchedulingModelsAppointmentsAppointmentAddon = z.object({ID: z.number().int().optional(), AppointmentTypeReference: z.number().int().optional(), ServiceCategoryReference: z.number().int().optional(), StaffAppointmentTypeReference: z.number().int().optional(), StaffReference: z.number().int().optional(), AppointmentReference: z.number().int().optional()}); export const mindbodyContractSchedulingModelsAppointmentsAppointment = z.object({ID: z.number().int().optional(), ServiceCategoryReference: z.number().int().optional(), AppointmentTypeReference: z.number().int().optional(), StaffReference: z.number().int().optional(), AvailabilityReference: z.number().int().optional(), Range: mindbodyContractSchedulingModelsCommonDateTimeRange.optional(), LocationReference: z.number().int().optional(), ConsumerReference: z.number().int().optional(), PrepTime: z.number().int().optional(), FinishTime: z.number().int().optional(), WrapupTime: z.number().int().optional(), ResourceReferences: z.array(z.number().int()).optional(), ApptGroupID: z.number().int().optional(), Addons: z.array(mindbodyContractSchedulingModelsAppointmentsAppointmentAddon).optional(), Recurring: z.boolean().optional()}); export const mindbodyContractSchedulingModelsAppointmentsAppointmentNotes = z.object({AppointmentReference: z.number().int().optional(), Notes: z.string().optional()}); export const mindbodyContractSchedulingModelsAppointmentsAppointmentReservationInfo = z.object({AppointmentReference: z.number().int().optional(), ReservedByClientReference: z.number().int().optional(), ReservedFor: z.string().optional(), GenderPreference: z.enum(["Male", "Female", "None"]).optional()}); export const mindbodyContractSchedulingModelsAppointmentsAppointmentStatus = z.object({AppointmentReference: z.number().int().optional(), Arrived: z.boolean().optional(), Confirmed: z.boolean().optional(), Completed: z.boolean().optional(), BookedOnline: z.boolean().optional(), Cancelled: z.boolean().optional(), RequestedStaffReference: z.number().int().optional(), BookedBy: z.number().int().optional(), ConfirmedBy: z.number().int().optional(), ModifiedDate: z.string().optional(), ConfirmedDate: z.string().optional()}); export const mindbodyContractSchedulingModelsAppointmentsAppointmentPaymentInfo = z.object({AppointmentReference: z.number().int().optional(), PaymentReference: z.number().int().optional(), PaymentDescription: z.string().optional(), StaffGetsPaid: z.boolean().optional(), NumberDeducted: z.number().int().optional()}); export const mindbodyRestApiDtoModelsSiteAppointmentsBuildAppointmentsResponse = z.object({Appointments: z.record(z.string(), mindbodyContractSchedulingModelsAppointmentsAppointment).optional(), AppointmentNotes: z.record(z.string(), mindbodyContractSchedulingModelsAppointmentsAppointmentNotes).optional(), AppointmentReservationInfo: z.record(z.string(), mindbodyContractSchedulingModelsAppointmentsAppointmentReservationInfo).optional(), AppointmentStatus: z.record(z.string(), mindbodyContractSchedulingModelsAppointmentsAppointmentStatus).optional(), AppointmentPaymentInfo: z.record(z.string(), mindbodyContractSchedulingModelsAppointmentsAppointmentPaymentInfo).optional(), AppointmentAddOnIds: z.record(z.string(), z.array(z.number().int())).optional(), Errors: z.array(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 }; /** * Gets appointment details. * Takes a list of appointment ids and returns dictionary of appointment and its related objects. * * GET /Business/Schedules/Appointments */ export const getApiBusinessSchedulesAppointments = async (args: GetApiBusinessSchedulesAppointmentsArgs, options?: GetApiBusinessSchedulesAppointmentsOptions) => { const {baseUrl = "https://api.mindbodyonline.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.SiteId != null) headers.set("SiteId", String(args.SiteId)) for (const item of args.appointmentId ?? []) query.append("appointmentId", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/Business/Schedules/Appointments${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(mindbodyRestApiDtoModelsSiteAppointmentsBuildAppointmentsResponse, await res.json()) };