import {z} from 'zod' export type GetApiConsumerSchedulesLocationLocationIdAppointmentsStaffBookableTimeRangesArgs = {Authorization: string, SiteId: number, locationId: number, appointmentTypeId: number, staffId: Array, start: string, end: string, dependentId?: string | undefined, ignoreMembershipRestrictions?: boolean | undefined}; export type GetApiConsumerSchedulesLocationLocationIdAppointmentsStaffBookableTimeRangesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mindbodyContractSchedulingModelsStaffAppointmentTypesStaffAppointmentType = z.object({ID: z.number().int().optional(), StaffReference: z.number().int().optional(), AppointmentTypeReference: z.number().int().optional(), Active: z.boolean().optional(), Duration: z.number().int().optional(), PrepTime: z.number().int().optional(), FinishTime: z.number().int().optional(), PerStaffPrice: z.number().optional(), SmartBookingLengthApplied: z.boolean().optional()}); export const mindbodyContractSchedulingModelsCommonDateTimeRange = z.object({Start: z.string().optional(), End: z.string().optional()}); export const mindbodyContractSchedulingResponsesBuildBookableTimeRangesResponse = z.object({StaffAppointmentTypes: z.record(z.string(), z.array(mindbodyContractSchedulingModelsStaffAppointmentTypesStaffAppointmentType)).optional(), BookableTimeRanges: z.record(z.string(), z.record(z.string(), z.array(mindbodyContractSchedulingModelsCommonDateTimeRange))).optional(), ActiveTimes: z.array(z.string()).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 }; /** * List of bookable time ranges, appointment types, and staff appointment type details. * Location Id,Appointment type Id is required. * Staff id is optional. Can pass multiple staffId params * Date part is requried, time part is optional. * * GET /Consumer/Schedules/Location/{locationId}/Appointments/StaffBookableTimeRanges */ export const getApiConsumerSchedulesLocationLocationIdAppointmentsStaffBookableTimeRanges = async (args: GetApiConsumerSchedulesLocationLocationIdAppointmentsStaffBookableTimeRangesArgs, options?: GetApiConsumerSchedulesLocationLocationIdAppointmentsStaffBookableTimeRangesOptions) => { 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.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.SiteId != null) headers.set("SiteId", String(args.SiteId)) if (args.appointmentTypeId != null) query.append("appointmentTypeId", String(args.appointmentTypeId)) for (const item of args.staffId ?? []) query.append("staffId", String(item)) if (args.start != null) query.append("start", String(args.start)) if (args.end != null) query.append("end", String(args.end)) if (args.dependentId != null) query.append("dependentId", String(args.dependentId)) if (args.ignoreMembershipRestrictions != null) query.append("ignoreMembershipRestrictions", String(args.ignoreMembershipRestrictions)) const url = `${baseUrl.replace(/\/+$/, '')}/Consumer/Schedules/Location/${encodeURIComponent(String(args.locationId))}/Appointments/StaffBookableTimeRanges${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(mindbodyContractSchedulingResponsesBuildBookableTimeRangesResponse, await res.json()) };