import { apiGet, apiPatch } from "@/api/client";

export interface ShippingStat {
  label: string;
  value: string;
  tone?: string | null;
}

export interface ShippingCarrierLoad {
  label: string;
  value: string;
}

export interface ShippingOverviewResponse {
  stats: ShippingStat[];
  carriers: ShippingCarrierLoad[];
  highlighted_route: string;
}

export interface ShipmentSummary {
  shipment_id: string;
  order_id: string;
  carrier: string;
  destination: string;
  tracking_number: string;
  status: string;
  eta: string;
  last_event: string;
}

export interface ShipmentStatusTransition {
  shipment_id: string;
  previous_status: string;
  status: string;
  previous_last_event: string;
  last_event: string;
}

export function fetchShippingOverview(accessToken: string) {
  return apiGet<ShippingOverviewResponse>("/shipping/overview", { accessToken });
}

export function fetchShipments(accessToken: string) {
  return apiGet<ShipmentSummary[]>("/shipping/shipments", { accessToken });
}

export function updateShipmentStatus(
  shipmentId: string,
  accessToken: string,
  body: { status: string; last_event: string; eta?: string },
) {
  return apiPatch<ShipmentStatusTransition>(
    `/shipping/shipments/${shipmentId}/status`,
    { accessToken, body },
  );
}
