import {z} from 'zod' export type MindbodyContractSchedulingModelsCommonDateTimeRange = {Start?: string | undefined, End?: string | undefined}; export type MindbodyContractSchedulingModelsAppointmentTypesAppointmentType = {ID?: number | undefined, ServiceCategoryReference?: number | undefined, ServiceCategoryGroupReferences?: Array | undefined, Name?: string | undefined, Active?: boolean | undefined, Deleted?: boolean | undefined, PayrollIdentifier?: string | undefined, NumberDeducted?: number | undefined, Description?: string | undefined, DefaultTimeLength?: number | undefined, AddOn?: boolean | undefined, BackbarAmount?: number | undefined, Capacity?: number | undefined, ResourceRequired?: boolean | undefined, ShowInConsumerMode?: boolean | undefined, Category?: string | undefined, CategoryId?: number | undefined, Subcategory?: string | undefined, SubcategoryId?: number | undefined}; export type MindbodyContractSchedulingModelsStaffAppointmentTypesStaffAppointmentType = {ID?: number | undefined, StaffReference?: number | undefined, AppointmentTypeReference?: number | undefined, Active?: boolean | undefined, Duration?: number | undefined, PrepTime?: number | undefined, FinishTime?: number | undefined, PerStaffPrice?: number | undefined, SmartBookingLengthApplied?: boolean | undefined}; export type MindbodyContractSchedulingModelsAppointmentsAddonAppointmentRequest = {ID?: number | undefined, SessionTypeID?: number | undefined, SessionTypeName?: string | undefined, StaffID?: number | undefined, StaffName?: string | undefined, PaymentApplied?: boolean | undefined, AppointmentType?: MindbodyContractSchedulingModelsAppointmentTypesAppointmentType | undefined, StaffAppointmentType?: MindbodyContractSchedulingModelsStaffAppointmentTypesStaffAppointmentType | undefined}; export type MindbodyContractSchedulingModelsAppointmentsAppointmentBookingRequest = {AppointmentTypeReference?: number | undefined, StaffReference?: number | undefined, AvailabilityReference?: number | undefined, Range?: MindbodyContractSchedulingModelsCommonDateTimeRange | undefined, LocationReference?: number | undefined, ConsumerReference?: number | undefined, Notes?: string | undefined, ReservedByConsumerReference?: number | undefined, ReservedFor?: string | undefined, ResourceReferences?: Array | undefined, GenderPreference?: ('Male' | 'Female' | 'None') | undefined, PrepTime?: number | undefined, FinishTime?: number | undefined, WrapupTime?: number | undefined, TrainerRequested?: boolean | undefined, RestSource?: string | undefined, Recurring?: boolean | undefined, RecurringAppointmentGroupId?: number | undefined, Addons?: Array | undefined}; export type CreateApiConsumerSchedulesLocationLocationIdAppointmentsArgs = {Authorization: string, SiteId: number, locationId: number, checkVerified?: boolean | undefined, searchId?: number | undefined, userId?: string | undefined, creditCardTokenId?: string | undefined, body: Array}; export type CreateApiConsumerSchedulesLocationLocationIdAppointmentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiConsumerSchedulesLocationLocationIdAppointmentsResponse = z.object({}); 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 }; /** * Books single or multiple appointments and sends booking confirmation email. * Makes single or multiple appointment requests and sends appointment requested email if booking option is turned off. * Books and applies payment for single appointment if payment is required and sends booking confirmation email. * Location Id,StaffReference, AppointmentTypeReference, Range is required. * checkVerified is a boolean used for Connect on versions above 2.0.4. Returns booked appointment details * * POST /Consumer/Schedules/Location/{locationId}/Appointments */ export const createApiConsumerSchedulesLocationLocationIdAppointments = async (args: CreateApiConsumerSchedulesLocationLocationIdAppointmentsArgs, options?: CreateApiConsumerSchedulesLocationLocationIdAppointmentsOptions) => { 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)) if (args.checkVerified != null) query.append("checkVerified", String(args.checkVerified)) if (args.searchId != null) query.append("searchId", String(args.searchId)) if (args.userId != null) query.append("userId", String(args.userId)) if (args.creditCardTokenId != null) query.append("creditCardTokenId", String(args.creditCardTokenId)) const url = `${baseUrl.replace(/\/+$/, '')}/Consumer/Schedules/Location/${encodeURIComponent(String(args.locationId))}/Appointments${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(createApiConsumerSchedulesLocationLocationIdAppointmentsResponse, await res.json()) };