export type CustomerStatus = "Active" | "Pending" | "Inactive";
export type CustomerType = "Importer" | "Exporter" | "Supplier";

export interface Customer {
  id: number;
  name: string;
  email: string;
  company: string;
  status: CustomerStatus;
  customerType: CustomerType;
  phone: string;
  tinNumber: string;
  city: string;
  country: string;
  address: string;
  notes: string;
  documentsComplete: boolean;
}

const seedCustomers: Customer[] = [
  {
    id: 1,
    name: "Abel Tesfaye",
    email: "abel@example.com",
    company: "Addis Logistics",
    status: "Active",
    customerType: "Importer",
    phone: "+251 911 234 567",
    tinNumber: "0012345678",
    city: "Addis Ababa",
    country: "Ethiopia",
    address: "Bole Road, Sub-City 03, Building 17",
    notes: "Top-tier importer. Prefers weekly invoicing.",
    documentsComplete: false,
  },
  {
    id: 2,
    name: "Sara Bekele",
    email: "sara@example.com",
    company: "Blue Nile Trading",
    status: "Pending",
    customerType: "Exporter",
    phone: "+251 922 345 678",
    tinNumber: "0023456789",
    city: "Dire Dawa",
    country: "Ethiopia",
    address: "Industrial Park, Zone B, Warehouse 4",
    notes: "Awaiting compliance documents.",
    documentsComplete: false,
  },
  {
    id: 3,
    name: "Henok Alemu",
    email: "henok@example.com",
    company: "Ethio Freight",
    status: "Inactive",
    customerType: "Supplier",
    phone: "+251 933 456 789",
    tinNumber: "0034567890",
    city: "Djibouti City",
    country: "Djibouti",
    address: "Port Quarter, Avenue 26, Block 9",
    notes: "Account paused since last quarter.",
    documentsComplete: true,
  },
];

const extras: Array<{ name: string; company: string; city: string; country: string }> = [
  { name: "Yohannes Girma", company: "Habesha Imports", city: "Addis Ababa", country: "Ethiopia" },
  { name: "Meron Asfaw", company: "Sheba Trading", city: "Adama", country: "Ethiopia" },
  { name: "Daniel Kebede", company: "Awash Cargo", city: "Hawassa", country: "Ethiopia" },
  { name: "Liya Tadesse", company: "Lalibela Logistics", city: "Bahir Dar", country: "Ethiopia" },
  { name: "Samuel Worku", company: "Rift Valley Freight", city: "Mekelle", country: "Ethiopia" },
  { name: "Hanna Mulugeta", company: "Simien Exports", city: "Gondar", country: "Ethiopia" },
  { name: "Bereket Hailu", company: "Omo River Co.", city: "Jimma", country: "Ethiopia" },
  { name: "Tigist Wolde", company: "Tana Shipping", city: "Dessie", country: "Ethiopia" },
  { name: "Kalkidan Mesfin", company: "Coffee Belt Traders", city: "Addis Ababa", country: "Ethiopia" },
  { name: "Nahom Solomon", company: "Highland Freight", city: "Harar", country: "Ethiopia" },
  { name: "Ali Mohamed", company: "Red Sea Cargo", city: "Djibouti City", country: "Djibouti" },
  { name: "Fatima Hassan", company: "Gulf Logistics", city: "Tadjoura", country: "Djibouti" },
  { name: "Omar Ibrahim", company: "Bab-el-Mandeb Trading", city: "Ali Sabieh", country: "Djibouti" },
  { name: "Amina Said", company: "Horn of Africa Imports", city: "Dikhil", country: "Djibouti" },
  { name: "Yusuf Abdulahi", company: "Saharan Exports", city: "Obock", country: "Djibouti" },
  { name: "Selam Negash", company: "Equator Freight", city: "Arba Minch", country: "Ethiopia" },
  { name: "Mikias Lemma", company: "Gibe Trading", city: "Sodo", country: "Ethiopia" },
];

const statuses: CustomerStatus[] = ["Active", "Pending", "Inactive"];
const types: CustomerType[] = ["Importer", "Exporter", "Supplier"];

const generated: Customer[] = extras.map((entry, i) => {
  const id = seedCustomers.length + i + 1;
  return {
    id,
    name: entry.name,
    email: `${entry.name.toLowerCase().replace(/\s+/g, ".")}@example.com`,
    company: entry.company,
    status: statuses[i % statuses.length] as CustomerStatus,
    customerType: types[i % types.length] as CustomerType,
    phone: `+251 9${String(40 + i).padStart(2, "0")} ${String(100 + i * 13).slice(0, 3)} ${String(200 + i * 17).slice(0, 3)}`,
    tinNumber: String(40000000 + i * 12345).padStart(10, "0"),
    city: entry.city,
    country: entry.country,
    address: `Block ${i + 1}, Street ${10 + i}, Quarter ${(i % 5) + 1}`,
    notes: `Mock customer #${id}.`,
    documentsComplete: i % 3 === 0,
  };
});

export const customers: Customer[] = [...seedCustomers, ...generated];

export function getCustomerById(id: number | string): Customer | undefined {
  const numericId = typeof id === "string" ? Number(id) : id;
  return customers.find((c) => c.id === numericId);
}
