import {z} from 'zod' export type GetApiApiBusinessBusinessIdBranchBranchIdServiceArgs = {businessId: string, branchId: string, category_id?: string | undefined, includeArchived?: boolean | undefined, fetch_online_category?: boolean | undefined, fetch_addon_services?: boolean | undefined, service_type?: string | undefined, size?: number | undefined, page?: number | undefined}; export type GetApiApiBusinessBusinessIdBranchBranchIdServiceOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const priceStaffCategory = z.object({id: z.string().optional(), price: z.number().optional()}); export const staffCategories = z.object({prices: z.array(priceStaffCategory).optional()}); export const userDuration = z.object({userRef: z.string().optional(), duration: z.number().int().optional()}); export const userGapTime = z.object({userRef: z.string().optional(), gapTime: z.number().int().optional()}); export const department = z.object({id: z.string().optional(), name: z.string().optional()}); export const internetServiceCategory = z.object({id: z.string().optional(), name: z.string().optional()}); export const userPrice = z.object({userRef: z.string().optional(), price: z.number().optional()}); export const service = z.object({serviceId: z.string().optional(), version: z.number().int().optional(), archived: z.boolean().optional(), categoryId: z.string().optional(), duration: z.number().int().optional(), gapTime: z.number().int().optional(), name: z.string().optional(), price: z.number().optional(), disqualifiedStaff: z.array(z.string()).optional(), machines: z.array(z.string()).optional(), rooms: z.array(z.string()).optional(), taxRates: z.array(z.string()).optional(), internetName: z.string().optional(), staffCategories: staffCategories.optional(), userDurations: z.array(userDuration).optional(), userGapTimes: z.array(userGapTime).optional(), department: department.optional(), categoryName: z.string().optional(), internetEnabled: z.boolean().optional(), internetDescription: z.string().optional(), internetServiceCategories: z.array(internetServiceCategory).optional(), addonServiceIds: z.array(z.string()).optional(), isAddonOnly: z.boolean().optional(), userPrices: z.array(userPrice).optional()}); export const pageMetadata = z.object({size: z.number().int().optional(), totalElements: z.number().int().optional(), totalPages: z.number().int().optional(), number: z.number().int().optional()}); export const dataPagedModelService = z.object({_embedded: z.object({services: z.array(service).optional()}).optional(), page: pageMetadata.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 branch services * * GET /api/business/{businessId}/branch/{branchId}/service */ export const getApiApiBusinessBusinessIdBranchBranchIdService = async (args: GetApiApiBusinessBusinessIdBranchBranchIdServiceArgs, options?: GetApiApiBusinessBusinessIdBranchBranchIdServiceOptions) => { const {baseUrl = "http://api-gateway-eu.phorest.com/third-party-api-server", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.category_id != null) query.append("category_id", String(args.category_id)) if (args.includeArchived != null) query.append("includeArchived", String(args.includeArchived)) if (args.fetch_online_category != null) query.append("fetch_online_category", String(args.fetch_online_category)) if (args.fetch_addon_services != null) query.append("fetch_addon_services", String(args.fetch_addon_services)) if (args.service_type != null) query.append("service_type", String(args.service_type)) if (args.size != null) query.append("size", String(args.size)) if (args.page != null) query.append("page", String(args.page)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/business/${encodeURIComponent(String(args.businessId))}/branch/${encodeURIComponent(String(args.branchId))}/service${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(dataPagedModelService, await res.json()) };