import {z} from 'zod' export type MindbodyRestApiCommonModelsSchedulesAvailabilitySchedule = {AvailabilityScheduleId?: number | undefined, GroupId?: number | undefined, StaffReference?: number | undefined, Updated?: string | undefined, Created?: string | undefined, Status?: ('Public' | 'Masked' | 'Hidden') | undefined, LocationReference?: number | undefined, ServiceCategoryReferences?: Array | undefined, DaysOfWeek?: (Array<'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday'>) | undefined, StartTime?: string | undefined, EndTime?: string | undefined, StartDate?: string | undefined, EndDate?: string | undefined}; export type CreateApiBusinessSchedulesAvailabilityAddArgs = {Authorization: string, SiteId: number, body: Array}; export type CreateApiBusinessSchedulesAvailabilityAddOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mindbodyRestApiCommonModelsSchedulesAvailabilitySchedule = z.object({AvailabilityScheduleId: z.number().int().optional(), GroupId: z.number().int().optional(), StaffReference: z.number().int().optional(), Updated: z.string().optional(), Created: z.string().optional(), Status: z.enum(["Public", "Masked", "Hidden"]).optional(), LocationReference: z.number().int().optional(), ServiceCategoryReferences: z.array(z.number().int()).optional(), DaysOfWeek: z.array(z.enum(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"])).optional(), StartTime: z.string().optional(), EndTime: z.string().optional(), StartDate: z.string().optional(), EndDate: z.string().optional()}); export const mindbodyRestApiCommonModelsResultsSchedulesAddAvailabilityScheduleResponse = z.object({AvailabilitySchedule: z.array(mindbodyRestApiCommonModelsSchedulesAvailabilitySchedule).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 }; /** * Takes a list of AvailabilitySchedules and adds them to the schedule. Returns a list of AvailabilitySchedules with Id. * The following are required parameters: DaysOfWeek,StartTime,EndTime,StartDate,EndDate * * POST /Business/Schedules/Availability/Add */ export const createApiBusinessSchedulesAvailabilityAdd = async (args: CreateApiBusinessSchedulesAvailabilityAddArgs, options?: CreateApiBusinessSchedulesAvailabilityAddOptions) => { 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/Add${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(mindbodyRestApiCommonModelsResultsSchedulesAddAvailabilityScheduleResponse, await res.json()) };