import {z} from 'zod' export type MindbodyRestApiDtoModelsSiteSchedulesAvailabilitySchedule = {AvailabilityScheduleId?: number | undefined, LocationReference?: number | undefined, StaffReference?: number | undefined, DaysOfWeek?: Array | undefined, StartTime?: string | undefined, EndTime?: string | undefined, StartDate?: string | undefined, EndDate?: string | undefined, GroupId?: number | undefined, Updated?: string | undefined, Created?: string | undefined, Status?: ('Public' | 'Masked' | 'Hidden') | undefined, ServiceCategoryReferences?: Array | undefined}; export type CreateApiBusinessSchedulesAvailabilitySearchArgs = {Authorization: string, SiteId: number, body: Array}; export type CreateApiBusinessSchedulesAvailabilitySearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mindbodyRestApiDtoModelsSiteSchedulesAvailabilitySchedule = z.object({AvailabilityScheduleId: z.number().int().optional(), LocationReference: z.number().int().optional(), StaffReference: z.number().int().optional(), DaysOfWeek: z.array(z.string()).optional(), StartTime: z.string().optional(), EndTime: z.string().optional(), StartDate: z.string().optional(), EndDate: z.string().optional(), GroupId: z.number().int().optional(), Updated: z.string().optional(), Created: z.string().optional(), Status: z.enum(["Public", "Masked", "Hidden"]).optional(), ServiceCategoryReferences: z.array(z.number().int()).optional()}); export const mindbodyRestApiDtoModelsSiteControllersSearchAvailabilityResponse = z.object({AvailabilitySchedules: z.array(mindbodyRestApiDtoModelsSiteSchedulesAvailabilitySchedule).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 }; /** * Searches for availability schedule details for specific staff. * * POST /Business/Schedules/Availability/Search */ export const createApiBusinessSchedulesAvailabilitySearch = async (args: CreateApiBusinessSchedulesAvailabilitySearchArgs, options?: CreateApiBusinessSchedulesAvailabilitySearchOptions) => { const {baseUrl = "https://api.mindbodyonline.com", 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.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.SiteId != null) headers.set("SiteId", String(args.SiteId)) const url = `${baseUrl.replace(/\/+$/, '')}/Business/Schedules/Availability/Search${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(mindbodyRestApiDtoModelsSiteControllersSearchAvailabilityResponse, await res.json()) };