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 MindbodyContractSchedulingModelsAppointmentRequestsAppointmentRequestConfirmationRequest = {AppointmentRequestReference?: number | undefined, 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 CreateApiBusinessSchedulesAppointmentRequestsApproveArgs = {Authorization: string, SiteId: number, body: Array}; export type CreateApiBusinessSchedulesAppointmentRequestsApproveOptions = {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 mindbodyContractSchedulingModelsErrorsError = z.object({Description: z.string().optional(), Code: z.string().optional()}); export const mindbodyContractSchedulingResponsesStaffConfirmRequestResponse = 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(), Errors: z.array(z.string()).optional(), ErrorList: z.array(mindbodyContractSchedulingModelsErrorsError).optional(), BookingRolledBack: z.boolean().optional(), PostBookingProcessSuccess: z.boolean().optional(), AppointmentRequestDeleted: z.boolean().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 }; /** * Approves a single or multiple request(s) and sends the appointment request confirmation email. * Takes a list of appointment requests which includes AppointmentRequestReference, StaffReference, * AppointmentTypeReference, Range, ConsumerReference, LocationReference, ResourceReferences, AvailabilityReference. * * POST /Business/Schedules/AppointmentRequests/Approve */ export const createApiBusinessSchedulesAppointmentRequestsApprove = async (args: CreateApiBusinessSchedulesAppointmentRequestsApproveArgs, options?: CreateApiBusinessSchedulesAppointmentRequestsApproveOptions) => { 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/AppointmentRequests/Approve${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(mindbodyContractSchedulingResponsesStaffConfirmRequestResponse, await res.json()) };