import {z} from 'zod' export type AppointmentUpdateRequest = {appointmentId: string, version: number, appointmentDate?: string | undefined, startTime: string, endTime?: string | undefined, price?: number | undefined, staffId: string, roomId?: string | undefined, machineId?: string | undefined, confirmed?: boolean | undefined, serviceId?: string | undefined}; export type UpdateApiApiBusinessBusinessIdBranchBranchIdAppointmentAppointmentIdArgs = {businessId: string, branchId: string, appointmentId: string, force_selected_time?: boolean | undefined, body: AppointmentUpdateRequest}; export type UpdateApiApiBusinessBusinessIdBranchBranchIdAppointmentAppointmentIdOptions = {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 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 }; /** * Update an appointment * * PUT /api/business/{businessId}/branch/{branchId}/appointment/{appointmentId} */ export const updateApiApiBusinessBusinessIdBranchBranchIdAppointmentAppointmentId = async (args: UpdateApiApiBusinessBusinessIdBranchBranchIdAppointmentAppointmentIdArgs, options?: UpdateApiApiBusinessBusinessIdBranchBranchIdAppointmentAppointmentIdOptions) => { 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('content-type', "application/json") headers.set('accept', "application/json") if (args.force_selected_time != null) query.append("force_selected_time", String(args.force_selected_time)) 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/${encodeURIComponent(String(args.appointmentId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(appointmentResponse, await res.json()) };