import {z} from 'zod' export type GetApiApiBusinessBusinessIdBranchBranchIdAppointmentArgs = {businessId: string, branchId: string, from_date?: string | undefined, to_date?: string | undefined, staff_id?: string | undefined, room_id?: string | undefined, machine_id?: string | undefined, client_id?: string | undefined, fetch_canceled?: boolean | undefined, fetch_deleted?: boolean | undefined, fetch_archived?: boolean | undefined, updated_from?: string | undefined, updated_to?: string | undefined, fetch_online_category?: boolean | undefined, fetch_notes?: boolean | undefined, group_booking_id?: string | undefined, size?: number | undefined, page?: number | undefined, sort?: string | undefined}; export type GetApiApiBusinessBusinessIdBranchBranchIdAppointmentOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const internetServiceCategory = z.object({id: z.string().optional(), name: z.string().optional()}); export const appointmentResponse = z.object({appointmentId: z.string(), version: z.number().int(), appointmentDate: z.string().optional(), startTime: z.string(), endTime: z.string().optional(), price: z.number().optional(), staffId: z.string(), roomId: z.string().optional(), machineId: z.string().optional(), confirmed: z.boolean().optional(), serviceId: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), staffRequest: z.boolean().optional(), preferredStaff: z.boolean().optional(), clientId: z.string().optional(), serviceRewardId: z.string().optional(), courseId: z.string().optional(), courseName: z.string().optional(), clientCourseId: z.string().optional(), clientCourseItemId: z.string().optional(), purchasingBranchId: z.string().optional(), serviceGroupItemOptionId: z.string().optional(), serviceGroupId: z.string().optional(), parentServiceGroupId: z.string().optional(), serviceName: z.string().optional(), state: z.enum(["BOOKED", "CHECKED_IN", "PAID"]).optional(), activationState: z.enum(["RESERVED", "ACTIVE", "CANCELED"]).optional(), waitingListDateTime: z.string().optional(), depositAmount: z.number().optional(), depositDateTime: z.string().optional(), bookingId: z.string().optional(), source: z.string().optional(), groupBookingId: z.string().optional(), deleted: z.boolean().optional(), notes: z.string().optional(), internetServiceCategories: z.array(internetServiceCategory).optional(), branchId: z.string().optional(), isFinishAppointment: 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 dataPagedModelAppointmentResponse = z.object({_embedded: z.object({appointments: z.array(appointmentResponse).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 appointments * * GET /api/business/{businessId}/branch/{branchId}/appointment */ export const getApiApiBusinessBusinessIdBranchBranchIdAppointment = async (args: GetApiApiBusinessBusinessIdBranchBranchIdAppointmentArgs, options?: GetApiApiBusinessBusinessIdBranchBranchIdAppointmentOptions) => { 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.client_id != null) query.append("client_id", String(args.client_id)) if (args.fetch_canceled != null) query.append("fetch_canceled", String(args.fetch_canceled)) if (args.fetch_deleted != null) query.append("fetch_deleted", String(args.fetch_deleted)) if (args.fetch_archived != null) query.append("fetch_archived", String(args.fetch_archived)) if (args.updated_from != null) query.append("updated_from", String(args.updated_from)) if (args.updated_to != null) query.append("updated_to", String(args.updated_to)) if (args.fetch_online_category != null) query.append("fetch_online_category", String(args.fetch_online_category)) if (args.fetch_notes != null) query.append("fetch_notes", String(args.fetch_notes)) if (args.group_booking_id != null) query.append("group_booking_id", String(args.group_booking_id)) if (args.size != null) query.append("size", String(args.size)) if (args.page != null) query.append("page", String(args.page)) if (args.sort != null) query.append("sort", String(args.sort)) 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))}/appointment${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(dataPagedModelAppointmentResponse, await res.json()) };