import {z} from 'zod' export type GetApiApiBusinessBusinessIdBranchBranchIdBreakArgs = {businessId: string, branchId: string, from_date: string, to_date: string, staff_id?: string | undefined, room_id?: string | undefined, machine_id?: string | undefined, size?: number | undefined, page?: number | undefined}; export type GetApiApiBusinessBusinessIdBranchBranchIdBreakOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const breakResponse = z.object({breakDate: z.string().optional(), startTime: z.string().optional(), endTime: z.string().optional(), staffId: z.string().optional(), roomId: z.string().optional(), machineId: z.string().optional(), label: z.string().optional(), paidBreak: z.boolean().optional(), breakId: z.string().optional(), version: z.number().int().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 dataPagedModelBreakResponse = z.object({_embedded: z.object({breaks: z.array(breakResponse).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 breaks * * GET /api/business/{businessId}/branch/{branchId}/break */ export const getApiApiBusinessBusinessIdBranchBranchIdBreak = async (args: GetApiApiBusinessBusinessIdBranchBranchIdBreakArgs, options?: GetApiApiBusinessBusinessIdBranchBranchIdBreakOptions) => { 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.from_date != null) query.append("from_date", String(args.from_date)) if (args.to_date != null) query.append("to_date", String(args.to_date)) if (args.staff_id != null) query.append("staff_id", String(args.staff_id)) if (args.room_id != null) query.append("room_id", String(args.room_id)) if (args.machine_id != null) query.append("machine_id", String(args.machine_id)) 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))}/break${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(dataPagedModelBreakResponse, await res.json()) };