import {z} from 'zod' export type GetApiApiBusinessBusinessIdBranchBranchIdServiceServiceIdArgs = {businessId: string, branchId: string, serviceId: string, fetch_online_category?: boolean | undefined, fetch_addon_services?: boolean | undefined}; export type GetApiApiBusinessBusinessIdBranchBranchIdServiceServiceIdOptions = {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 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 }; /** * Retrieve a branch service * * GET /api/business/{businessId}/branch/{branchId}/service/{serviceId} */ export const getApiApiBusinessBusinessIdBranchBranchIdServiceServiceId = async (args: GetApiApiBusinessBusinessIdBranchBranchIdServiceServiceIdArgs, options?: GetApiApiBusinessBusinessIdBranchBranchIdServiceServiceIdOptions) => { 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.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 (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/${encodeURIComponent(String(args.serviceId))}${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(service, await res.json()) };