import {z} from 'zod' export type GetApiApiBusinessBusinessIdClientcourseArgs = {businessId: string, branch_id?: string | undefined, client_id?: string | undefined, includeArchived?: boolean | undefined, includeUsedCourseItems?: boolean | undefined, size?: number | undefined, page?: number | undefined}; export type GetApiApiBusinessBusinessIdClientcourseOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const clientCourseItem = z.object({clientCourseItemId: z.string().optional(), courseItemId: z.string().optional(), serviceId: z.string().optional(), initialUnits: z.number().int().optional(), remainingUnits: z.number().int().optional(), grossPrice: z.number().optional(), netPrice: z.number().optional()}); export const clientCourseResponse = z.object({clientCourseId: z.string().optional(), archived: z.boolean().optional(), purchaseDate: z.string().optional(), expiryDate: z.string().optional(), clientId: z.string().optional(), purchasingBranchId: z.string().optional(), courseId: z.string().optional(), courseName: z.string().optional(), grossPrice: z.number().optional(), netPrice: z.number().optional(), clientCourseItems: z.array(clientCourseItem).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 dataPagedModelClientCourseResponse = z.object({_embedded: z.object({clientCourses: z.array(clientCourseResponse).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 client courses * * GET /api/business/{businessId}/clientcourse */ export const getApiApiBusinessBusinessIdClientcourse = async (args: GetApiApiBusinessBusinessIdClientcourseArgs, options?: GetApiApiBusinessBusinessIdClientcourseOptions) => { 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.branch_id != null) query.append("branch_id", String(args.branch_id)) if (args.client_id != null) query.append("client_id", String(args.client_id)) if (args.includeArchived != null) query.append("includeArchived", String(args.includeArchived)) if (args.includeUsedCourseItems != null) query.append("includeUsedCourseItems", String(args.includeUsedCourseItems)) 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))}/clientcourse${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(dataPagedModelClientCourseResponse, await res.json()) };