import {z} from 'zod' export type GetApiSetupV1ResourcesIdAllocationsArgs = {id: string, startDate?: string | undefined, endDate?: string | undefined, offset?: number | undefined, limit?: number | undefined}; export type GetApiSetupV1ResourcesIdAllocationsOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const repeatViewModel = z.object({frequency: z.string().nullable().optional(), interval: z.number().int().optional(), weekdays: z.string().nullable().optional(), monthDay: z.string().nullable().optional(), monthType: z.string().nullable().optional()}); export const resourceAllocationViewModel = z.object({object: z.string().nullable().optional(), id: z.number().int().optional(), businessId: z.number().int().optional(), resourceId: z.number().int().optional(), startDate: z.string().nullable().optional(), endDate: z.string().nullable().optional(), startTime: z.number().int().optional(), endTime: z.number().int().optional(), reason: z.string().nullable().optional(), repeats: z.boolean().optional(), repeat: repeatViewModel.optional(), deletedStatus: z.boolean().optional(), deletedTime: z.string().nullable().optional()}); export const resourceAllocationListViewModel = z.object({object: z.string().nullable().optional(), url: z.string().nullable().optional(), hasMore: z.boolean().optional(), count: z.number().int().optional(), total: z.number().int().optional(), data: z.array(resourceAllocationViewModel).nullable().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 }; /** * List Resource Allocations * * GET /setup/v1/resources/{id}/allocations */ export const getApiSetupV1ResourcesIdAllocations = async (args: GetApiSetupV1ResourcesIdAllocationsArgs, options?: GetApiSetupV1ResourcesIdAllocationsOptions) => { const {baseUrl = "https://sandbox-api.onsched.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/setup/v1/resources/${encodeURIComponent(String(args.id))}/allocations${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(resourceAllocationListViewModel, await res.json()) };