import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http' import type { ContainerManualNodeRequest, ContainerShippingNodeDetail } from '../types' const basePath = '/platform/v1/container-shipping-nodes' function normalize(raw: ContainerShippingNodeDetail): ContainerShippingNodeDetail { return { ...raw, containerBookingId: String(raw.containerBookingId), nodes: (raw.nodes || []).map((item) => ({ ...item, id: String(item.id), nodeSequence: Number(item.nodeSequence) })) } } export async function getContainerShippingNodes(containerBookingId: string): Promise { const response = await http.get, ApiEnvelope>(`${basePath}/${encodeURIComponent(containerBookingId)}`) return normalize(unwrapApiResponse(response)) } export async function appendContainerShippingNode(containerBookingId: string, idempotencyKey: string, request: ContainerManualNodeRequest): Promise { const response = await http.post, ApiEnvelope>(`${basePath}/${encodeURIComponent(containerBookingId)}`, request, { headers: { 'Idempotency-Key': idempotencyKey } }) return normalize(unwrapApiResponse(response)) }