import {z} from 'zod' export type GetApiApiBusinessBusinessIdClientClientIdServiceHistoryArgs = {businessId: string, clientId: string, size?: number | undefined, page?: number | undefined}; export type GetApiApiBusinessBusinessIdClientClientIdServiceHistoryOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const singleServiceHistory = z.object({appointmentId: z.string().optional(), staffId: z.string().optional(), serviceId: z.string().optional(), clientCourseItemId: z.string().optional(), groupBookingId: z.string().optional(), serviceCategoryId: z.string().optional(), serviceGroupId: z.string().optional(), serviceGroupItemOptionId: z.string().optional(), serviceRewardId: z.string().optional(), time: z.string().optional(), description: z.string().optional(), depositAmount: z.number().optional(), depositTime: z.string().optional(), duration: z.number().int().optional(), discount: z.number().optional(), fee: z.number().optional(), originalPrice: z.number().optional(), waitingList: z.boolean().optional(), checkedIn: z.boolean().optional(), cancelled: z.boolean().optional()}); export const clientServiceHistory = z.object({branchId: z.string().optional(), clientId: z.string().optional(), notes: z.string().optional(), systemNotes: z.string().optional(), date: z.string().optional(), bookingId: z.string().optional(), services: z.array(singleServiceHistory).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 dataPagedModelClientServiceHistory = z.object({_embedded: z.object({clientServiceHistories: z.array(clientServiceHistory).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 }; /** * Retrieve client's service histories * * GET /api/business/{businessId}/client/{clientId}/service-history */ export const getApiApiBusinessBusinessIdClientClientIdServiceHistory = async (args: GetApiApiBusinessBusinessIdClientClientIdServiceHistoryArgs, options?: GetApiApiBusinessBusinessIdClientClientIdServiceHistoryOptions) => { 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.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))}/client/${encodeURIComponent(String(args.clientId))}/service-history${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(dataPagedModelClientServiceHistory, await res.json()) };