import {z} from 'zod' export type CreateApiV2UsersCapacitySchedulesArgs = {body: {scheduleName: string, startDate: string, endDate?: string | undefined, locationID: number, userID?: number | undefined, profileID?: number | undefined, mondayCapacity?: number | undefined, tuesdayCapacity?: number | undefined, wednesdayCapacity?: number | undefined, thursdayCapacity?: number | undefined, fridayCapacity?: number | undefined, saturdayCapacity?: number | undefined, sundayCapacity?: number | undefined, mondayStartTime?: string | undefined, mondayEndTime?: string | undefined, tuesdayStartTime?: string | undefined, tuesdayEndTime?: string | undefined, wednesdayStartTime?: string | undefined, wednesdayEndTime?: string | undefined, thursdayStartTime?: string | undefined, thursdayEndTime?: string | undefined, fridayStartTime?: string | undefined, fridayEndTime?: string | undefined, saturdayStartTime?: string | undefined, saturdayEndTime?: string | undefined, sundayStartTime?: string | undefined, sundayEndTime?: string | undefined, rotationPatternEnabled?: boolean | undefined, rotationWeeksOn?: number | undefined, rotationWeeksOff?: number | undefined, scheduleNotes?: string | undefined, priority?: number | undefined, isActive?: boolean | undefined}}; export type CreateApiV2UsersCapacitySchedulesOptions = {baseUrl: string, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiV2UsersCapacitySchedulesResponse = z.object({scheduleID: z.number().int().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 }; /** * Create Capacity Schedule * * POST /v2/users/capacity/schedules */ export const createApiV2UsersCapacitySchedules = async (args: CreateApiV2UsersCapacitySchedulesArgs, options: CreateApiV2UsersCapacitySchedulesOptions) => { const {baseUrl, fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/users/capacity/schedules${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(createApiV2UsersCapacitySchedulesResponse, await res.json()) };