import { consignments } from "../consignments/consignments.mock";

export type ShipmentStatus = "In Transit" | "Delivered" | "Delayed";
export type ShipmentMode = "rail" | "truck" | "multimodal";

export interface Shipment {
  id: number;
  reference: string;
  consignmentId: number;
  consignmentReference: string;
  bookingReference: string;
  customer: string;
  originStation: string;
  destinationStation: string;
  mode: ShipmentMode;
  status: ShipmentStatus;
  currentLocation: string;
  eta: string;
  lastUpdate: string;
  progress: number;
}

const seedShipments: Array<{
  status: ShipmentStatus;
  currentLocation: string;
  eta: string;
  lastUpdate: string;
  progress: number;
  mode: ShipmentMode;
}> = [
  {
    status: "In Transit",
    currentLocation: "Awash Junction",
    eta: "2026-05-18",
    lastUpdate: "2 hours ago",
    progress: 45,
    mode: "rail",
  },
  {
    status: "Delivered",
    currentLocation: "Dire Dawa Depot",
    eta: "2026-05-12",
    lastUpdate: "Yesterday",
    progress: 100,
    mode: "truck",
  },
  {
    status: "In Transit",
    currentLocation: "Dire Dawa Yard",
    eta: "2026-05-17",
    lastUpdate: "30 minutes ago",
    progress: 70,
    mode: "rail",
  },
  {
    status: "Delayed",
    currentLocation: "Mieso",
    eta: "2026-05-19",
    lastUpdate: "5 hours ago",
    progress: 35,
    mode: "rail",
  },
  {
    status: "Delivered",
    currentLocation: "Adama Logistics Hub",
    eta: "2026-05-10",
    lastUpdate: "3 days ago",
    progress: 100,
    mode: "truck",
  },
  {
    status: "In Transit",
    currentLocation: "Mieso Crossing",
    eta: "2026-05-20",
    lastUpdate: "1 hour ago",
    progress: 55,
    mode: "multimodal",
  },
  {
    status: "Delayed",
    currentLocation: "Debre Markos",
    eta: "2026-05-16",
    lastUpdate: "6 hours ago",
    progress: 60,
    mode: "truck",
  },
  {
    status: "In Transit",
    currentLocation: "Awash Junction",
    eta: "2026-05-21",
    lastUpdate: "45 minutes ago",
    progress: 40,
    mode: "multimodal",
  },
  {
    status: "Delivered",
    currentLocation: "Djibouti Port",
    eta: "2026-05-09",
    lastUpdate: "5 days ago",
    progress: 100,
    mode: "rail",
  },
  {
    status: "In Transit",
    currentLocation: "Aysha Border",
    eta: "2026-05-19",
    lastUpdate: "20 minutes ago",
    progress: 80,
    mode: "rail",
  },
  {
    status: "Delivered",
    currentLocation: "Addis Ababa Warehouse",
    eta: "2026-05-11",
    lastUpdate: "4 days ago",
    progress: 100,
    mode: "truck",
  },
  {
    status: "Delayed",
    currentLocation: "Dire Dawa Yard",
    eta: "2026-05-22",
    lastUpdate: "12 hours ago",
    progress: 50,
    mode: "rail",
  },
];

export const shipments: Shipment[] = seedShipments.map((entry, i) => {
  const consignment = consignments[
    i % consignments.length
  ] as (typeof consignments)[number];
  const id = i + 1;
  return {
    id,
    reference: `SH-${String(id).padStart(3, "0")}`,
    consignmentId: consignment.id,
    consignmentReference: consignment.trackingNumber,
    bookingReference: consignment.bookingReference,
    customer: consignment.customer,
    originStation: consignment.originStation,
    destinationStation: consignment.destinationStation,
    mode: entry.mode,
    status: entry.status,
    currentLocation: entry.currentLocation,
    eta: entry.eta,
    lastUpdate: entry.lastUpdate,
    progress: entry.progress,
  };
});

export function getShipmentById(id: number | string): Shipment | undefined {
  const numericId = typeof id === "string" ? Number(id) : id;
  return shipments.find((s) => s.id === numericId);
}
