import {z} from 'zod' export type DeleteApiSetupV1ServicesAllocationsIdArgs = {id: string}; export type DeleteApiSetupV1ServicesAllocationsIdOptions = {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 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 }; /** * Delete Allocation * * DELETE /setup/v1/services/allocations/{id} */ export const deleteApiSetupV1ServicesAllocationsId = async (args: DeleteApiSetupV1ServicesAllocationsIdArgs, options?: DeleteApiSetupV1ServicesAllocationsIdOptions) => { 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 (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/setup/v1/services/allocations/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(serviceAllocationViewModel, await res.json()) };