import {z} from 'zod' export type RepeatInputModel = {frequency?: (string | null) | undefined, interval?: (number | null) | undefined, weekdays?: (string | null) | undefined, monthDay?: (number | null) | undefined, monthType?: (string | null) | undefined}; export type ServiceAllocationInputModel = {locationId?: (string | null) | undefined, resourceId?: (string | null) | undefined, startDate?: (string | null) | undefined, endDate?: (string | null) | undefined, startTime?: (number | null) | undefined, endTime?: (number | null) | undefined, reason?: (string | null) | undefined, bookingLimit?: number | undefined, repeats?: (boolean | null) | undefined, repeat?: RepeatInputModel | undefined}; export type ServiceAllocationsInputModel = {serviceAllocations?: (Array | null) | undefined}; export type CreateApiSetupV1ServicesIdAllocationsBulkArgs = {id: string, body: ServiceAllocationsInputModel}; export type CreateApiSetupV1ServicesIdAllocationsBulkOptions = {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 phoneViewModel = z.object({phoneType: z.string().nullable().optional(), homePhone: z.string().nullable().optional(), mobilePhone: z.string().nullable().optional(), businessPhone: z.string().nullable().optional(), businessPhoneExt: z.string().nullable().optional()}); export const addressViewModel = z.object({addressLine1: z.string().nullable().optional(), addressLine2: z.string().nullable().optional(), city: z.string().nullable().optional(), state: z.string().nullable().optional(), country: z.string().nullable().optional(), postalCode: z.string().nullable().optional()}); export const serviceAllocationViewModel = z.object({object: z.string().nullable().optional(), id: z.string().nullable().optional(), locationId: z.string().nullable().optional(), timezoneOffset: z.number().int().nullable().optional(), timezoneName: z.string().nullable().optional(), serviceId: z.string().nullable().optional(), serviceName: z.string().nullable().optional(), serviceDescription: z.string().nullable().optional(), serviceImageUrl: z.string().nullable().optional(), serviceDuration: z.number().int().optional(), reason: z.string().nullable().optional(), bookingLimit: z.number().int().optional(), bookingCount: z.number().int().optional(), startDate: z.string().nullable().optional(), endDate: z.string().nullable().optional(), startTime: z.number().int().optional(), endTime: z.number().int().optional(), repeats: z.boolean().optional(), repeat: repeatViewModel.optional(), deletedStatus: z.boolean().optional(), deletedTime: z.string().nullable().optional(), resourceId: z.string().nullable().optional(), resourceName: z.string().nullable().optional(), resourceDescription: z.string().nullable().optional(), resourceImageUrl: z.string().nullable().optional(), resourcePhone: phoneViewModel.optional(), resourceAddress: addressViewModel.optional()}); export const createApiSetupV1ServicesIdAllocationsBulkResponse = z.array(serviceAllocationViewModel); 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 Allocations Bulk * * POST /setup/v1/services/{id}/allocations/bulk */ export const createApiSetupV1ServicesIdAllocationsBulk = async (args: CreateApiSetupV1ServicesIdAllocationsBulkArgs, options?: CreateApiSetupV1ServicesIdAllocationsBulkOptions) => { const {baseUrl = "https://sandbox-api.onsched.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/setup/v1/services/${encodeURIComponent(String(args.id))}/allocations/bulk${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(createApiSetupV1ServicesIdAllocationsBulkResponse, await res.json()) };