import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http' import type { PlanningSource } from './planningApi' export interface CargoVerification { version: number; sourceVersion: string | null; destinationKey: string; sourcePackages: number | null; packageCount: number | null; shipmentReferences: string[]; remark: string | null; operatorName: string | null; verifiedAt: string } export interface CargoVerificationContext { source: PlanningSource; verification: CargoVerification | null; allocatedPackages: number; unknownAllocationCount: number; effectivePackages: number | null; availablePackages: number | null; sourceChanged: boolean; allowedActions: string[]; blockReasons: string[] } export interface CargoVerificationSource { sourceKey: string; customerId: string; destinationKey?: string } export interface SaveCargoVerification { destinationKey: string; expectedSourceVersion: string | null; expectedVersion: number; packageCount: number | null; shipmentReferences: string[]; remark: string | null; idempotencyKey: string } const path = (key: string) => `/platform/v1/last-leg/appointment-planning/sources/${encodeURIComponent(key)}/cargo-verification` export async function getCargoVerification(source: CargoVerificationSource) { return unwrapApiResponse(await http.get, ApiEnvelope>(path(source.sourceKey), { params: { customerId: source.customerId, destinationKey: source.destinationKey } })) } export async function saveCargoVerification(source: CargoVerificationSource, body: SaveCargoVerification) { return unwrapApiResponse(await http.post, ApiEnvelope>(path(source.sourceKey), body, { params: { customerId: source.customerId } })) }