import {z} from 'zod' export type MindbodyApiAreasBusinessSchedulesAppointmentsRequestsGetConsumerBookingTemplateRequest = {ConsumerId?: number | undefined, MaxDays?: number | undefined}; export type CreateApiBusinessSchedulingAppointmentsBookingTemplatesArgs = {SiteId: number, body: MindbodyApiAreasBusinessSchedulesAppointmentsRequestsGetConsumerBookingTemplateRequest}; export type CreateApiBusinessSchedulingAppointmentsBookingTemplatesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mindbodyContractSchedulingModelsCommonTimeRange = z.object({Start: z.string().optional(), End: z.string().optional()}); export const mindbodyContractSchedulingModelsBookingTemplatesBookingTemplateItem = z.object({Location: z.number().int().optional(), ServiceType: z.number().int().optional(), Range: mindbodyContractSchedulingModelsCommonTimeRange.optional(), Staff: z.number().int().optional(), Consumer: z.number().int().optional(), Resources: z.array(z.number().int()).optional(), Date: z.string().optional(), PrepTime: z.number().int().optional(), FinishTime: z.number().int().optional(), WrapupTime: z.number().int().optional(), MetaData: z.record(z.string(), z.object({})).optional()}); export const mindbodyContractSchedulingModelsBookingTemplatesBookingTemplate = z.object({Subscriber: z.number().int().optional(), BookingTemplateItems: z.array(mindbodyContractSchedulingModelsBookingTemplatesBookingTemplateItem).optional()}); export const mindbodyApiAreasBusinessSchedulesAppointmentsResponsesGetConsumerBookingTemplatesResponse = z.object({BookingTemplates: z.array(mindbodyContractSchedulingModelsBookingTemplatesBookingTemplate).optional(), MetaData: z.record(z.string(), z.object({})).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 booking templates based on passed in consumer ID and the max days to get. This call is intended to help make booking easier * by providing templates that have much of the information, needed to make an appointment, already filled out. The templates are * built based on the consumer's past appointment activity. * * POST /Business/Scheduling/Appointments/BookingTemplates */ export const createApiBusinessSchedulingAppointmentsBookingTemplates = async (args: CreateApiBusinessSchedulingAppointmentsBookingTemplatesArgs, options?: CreateApiBusinessSchedulingAppointmentsBookingTemplatesOptions) => { 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.SiteId != null) headers.set("SiteId", String(args.SiteId)) const url = `${baseUrl.replace(/\/+$/, '')}/Business/Scheduling/Appointments/BookingTemplates${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(mindbodyApiAreasBusinessSchedulesAppointmentsResponsesGetConsumerBookingTemplatesResponse, await res.json()) };