import {z} from 'zod' export type GetApiApiBusinessBusinessIdBranchBranchIdReviewArgs = {businessId: string, branchId: string, clientId?: string | undefined, clientName?: string | undefined, staffName?: string | undefined, reviewDate?: string | undefined, size?: number | undefined, page?: number | undefined}; export type GetApiApiBusinessBusinessIdBranchBranchIdReviewOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const reviewResponse = z.object({reviewId: z.string().optional(), clientId: z.string().optional(), clientFirstName: z.string().optional(), clientLastName: z.string().optional(), reviewDate: z.string().optional(), visitDate: z.string().optional(), staffId: z.string().optional(), staffFirstName: z.string().optional(), staffLastName: z.string().optional(), text: z.string().optional(), rating: z.number().int().optional(), facebookReview: z.boolean().optional(), twitterReview: z.boolean().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 dataPagedModelReviewResponse = z.object({_embedded: z.object({reviews: z.array(reviewResponse).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 reviews * * GET /api/business/{businessId}/branch/{branchId}/review */ export const getApiApiBusinessBusinessIdBranchBranchIdReview = async (args: GetApiApiBusinessBusinessIdBranchBranchIdReviewArgs, options?: GetApiApiBusinessBusinessIdBranchBranchIdReviewOptions) => { 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.clientId != null) query.append("clientId", String(args.clientId)) if (args.clientName != null) query.append("clientName", String(args.clientName)) if (args.staffName != null) query.append("staffName", String(args.staffName)) if (args.reviewDate != null) query.append("reviewDate", String(args.reviewDate)) 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))}/review${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(dataPagedModelReviewResponse, await res.json()) };