import {z} from 'zod' export type CreateApiHubManagementOccupanciesReserveAutomaticPackingFlexibleTimeScopeArgs = {body: {station?: string | undefined, station_slug?: unknown | undefined, time_scope?: {expected_check_in: string, expected_duration: string} | undefined, time_scope_date?: ({expected_check_in_date: string, expected_check_out_date?: string | undefined, expected_duration_days?: number | undefined}) | undefined, supplier?: string | undefined, package: {parcels: Array<{external_id: string | null, dimension: {width: number, height: number, length: number}, value?: (number | null) | undefined, promised_date?: string | undefined}>, external_id: string, shop?: string | undefined}, uuid?: string | undefined, order_date?: string | undefined, process: 'firstmile' | 'middlemile' | 'lastmile' | 'warehouse' | 'manual_lastmile' | 'personal_lastmile' | 'safe_box' | 'manual_firstmile', logistic_company?: string | undefined, picker?: string | undefined, dropper?: string | undefined, verbose_id?: string | undefined, password?: string | undefined, random?: boolean | undefined, picker_full_name?: string | undefined, cancel?: boolean | undefined}}; export type CreateApiHubManagementOccupanciesReserveAutomaticPackingFlexibleTimeScopeOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiHubManagementOccupanciesReserveAutomaticPackingFlexibleTimeScopeResponse = z.object({pk: z.number().int().optional(), uuid: z.string().optional(), verbose_id: z.string().min(1).max(50).optional(), status: z.string().optional(), process: z.string().optional(), station: z.object({uuid: z.string().optional(), address: z.string().max(400).nullable().optional(), location: z.string().optional(), nickname: z.string().max(255).nullable().optional(), postal_code: z.string().max(10).nullable().optional(), images: z.array(z.string()).optional(), districts: z.object({}).nullable().optional()}).optional(), shipment_external_id: z.string().min(1).optional(), picker_phone_number: z.string().min(1).optional(), picker_first_name: z.string().min(1).optional(), picker_last_name: z.string().min(1).optional(), picker_full_name: z.string().min(1).optional(), dropper_phone_number: z.string().min(1).optional(), dropper_first_name: z.string().min(1).optional(), dropper_last_name: z.string().min(1).optional(), users: z.object({supplier: z.string().optional(), picker: z.string().optional(), dropper: z.string().optional()}).optional(), dates: z.object({time_scope: z.object({expected_check_in: z.string(), expected_duration: z.string()}).optional(), order_date: z.string().optional(), check_in: z.string().optional(), check_out: z.string().optional(), cancel_date: z.string().optional(), extend_date: z.string().optional()}).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 }; /** * Reserves a single occupancy by automatic packing and flexible time scope. * * POST /hub-management/occupancies/reserve/automatic-packing/flexible-time-scope */ export const createApiHubManagementOccupanciesReserveAutomaticPackingFlexibleTimeScope = async (args: CreateApiHubManagementOccupanciesReserveAutomaticPackingFlexibleTimeScopeArgs, options?: CreateApiHubManagementOccupanciesReserveAutomaticPackingFlexibleTimeScopeOptions) => { const {baseUrl = "https://api.ganje.net/v1.1", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/hub-management/occupancies/reserve/automatic-packing/flexible-time-scope${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiHubManagementOccupanciesReserveAutomaticPackingFlexibleTimeScopeResponse, await res.json()) };