import type { FullContact } from "@/lib/contacts/types"

let _id = 0
function nextId(): string {
  return `demo-contact-${String(++_id).padStart(3, "0")}`
}

const NOW = 1716000000000

function c(
  partial: Omit<FullContact, "id" | "createdAt" | "updatedAt"> & {
    createdAt?: number
    updatedAt?: number
  }
): FullContact {
  return {
    id: nextId(),
    createdAt: NOW,
    updatedAt: NOW,
    ...partial,
  } as FullContact
}

const DEMO_CONTACT_AVATARS = Array.from({ length: 14 }, (_, index) =>
  `/demo/contacts/avatars/avatar-${String(index + 1).padStart(2, "0")}.jpg`
)

function applyDemoAvatars(contacts: FullContact[]): FullContact[] {
  let avatarIndex = 0
  return contacts.map((contact, index) => {
    if (index % 5 >= 2) return contact
    const avatarUrl = DEMO_CONTACT_AVATARS[avatarIndex % DEMO_CONTACT_AVATARS.length]
    avatarIndex += 1
    return { ...contact, avatarUrl }
  })
}

const RAW_DEMO_CONTACTS: FullContact[] = [
  c({
    firstName: "",
    lastName: "",
    phones: [{ value: "+33 6 47 82 19 03", label: "mobile" }],
    emails: [],
    notes: "Numéro reçu par SMS — identité inconnue.",
  }),
  c({
    firstName: "Atelier",
    lastName: "Nord",
    emails: [{ value: "contact@atelier-nord.fr", label: "work" }],
    phones: [{ value: "+33 1 76 54 32 10", label: "work" }],
    company: "Atelier Nord",
    website: "https://atelier-nord.fr",
    addresses: [
      {
        street: "18 rue de la Fonderie",
        city: "Lille",
        region: "Hauts-de-France",
        postalCode: "59000",
        country: "France",
        label: "Siège",
      },
    ],
  }),
  c({
    firstName: "Camille",
    lastName: "Visiteur",
    emails: [
      { value: "camille@demo.ulti", label: "work" },
      { value: "camille.visiteur@gmail.com", label: "personal" },
    ],
    phones: [{ value: "+33 6 12 00 45 78", label: "mobile" }],
    company: "Ultimail",
    department: "Produit",
    jobTitle: "Product Manager",
    nicknames: ["Cam"],
    labels: ["Équipe", "Favori"],
    birthday: { day: 14, month: 6, year: 1991 },
    notes: "Compte démo — calendrier personnel et boîte mail de démonstration.",
    addresses: [
      {
        street: "42 avenue Parmentier",
        city: "Paris",
        region: "Île-de-France",
        postalCode: "75011",
        country: "France",
        label: "home",
      },
    ],
    socialProfiles: [
      { value: "https://linkedin.com/in/camille-visiteur", label: "LinkedIn" },
      { value: "https://x.com/camille_visiteur", label: "X" },
    ],
    interactionCount: 128,
  }),
  c({
    firstName: "Léa",
    lastName: "Fontaine",
    emails: [
      { value: "lea.fontaine@atelier-nord.fr", label: "work" },
      { value: "lea.fontaine.perso@gmail.com", label: "personal" },
    ],
    phones: [
      { value: "+33 6 78 45 12 90", label: "mobile" },
      { value: "+33 1 76 54 32 11", label: "work" },
    ],
    company: "Atelier Nord",
    department: "Produit",
    jobTitle: "Head of Product",
    nicknames: ["Léa F."],
    labels: ["Client", "Produit"],
    birthday: { day: 3, month: 11, year: 1988 },
    notes: "Organisatrice du stand-up et du comité produit. Préfère les CR dans UltiDrive.",
    addresses: [
      {
        street: "18 rue de la Fonderie",
        city: "Lille",
        region: "Hauts-de-France",
        postalCode: "59000",
        country: "France",
        label: "work",
      },
      {
        street: "7 quai de la Loire",
        city: "Paris",
        region: "Île-de-France",
        postalCode: "75019",
        country: "France",
        label: "home",
      },
    ],
    socialProfiles: [
      { value: "https://linkedin.com/in/lea-fontaine", label: "LinkedIn" },
    ],
    interactionCount: 54,
  }),
  c({
    firstName: "Marc",
    lastName: "Delcourt",
    emails: [{ value: "marc@delcourt-conseil.com", label: "work" }],
    phones: [{ value: "+33 6 55 88 22 41", label: "mobile" }],
    company: "Delcourt Conseil",
    jobTitle: "Consultant senior",
    department: "Transformation digitale",
    addresses: [
      {
        street: "3 place de la Bourse",
        city: "Bordeaux",
        region: "Nouvelle-Aquitaine",
        postalCode: "33000",
        country: "France",
        label: "work",
      },
    ],
    interactionCount: 19,
  }),
  c({
    firstName: "Anaïs",
    lastName: "Rivet",
    emails: [
      { value: "anais.rivet@coop-numerique.org", label: "work" },
      { value: "anais.rivet@gmail.com", label: "personal" },
    ],
    phones: [{ value: "+33 6 33 77 44 12", label: "mobile" }],
    company: "Coop Numérique",
    department: "Communauté",
    jobTitle: "Community Lead",
    labels: ["Réseau"],
    addresses: [
      {
        street: "12 cours Julien",
        city: "Marseille",
        region: "Provence-Alpes-Côte d'Azur",
        postalCode: "13006",
        country: "France",
        label: "work",
      },
    ],
    socialProfiles: [
      { value: "https://linkedin.com/in/anais-rivet", label: "LinkedIn" },
      { value: "https://x.com/anais_rivet", label: "X" },
    ],
    interactionCount: 31,
  }),
  c({
    firstName: "Sophie",
    lastName: "Morel",
    emails: [{ value: "sophie@startup-io.fr", label: "work" }],
    phones: [
      { value: "+33 6 90 11 22 33", label: "mobile" },
      { value: "+33 1 84 88 12 00", label: "work" },
    ],
    company: "Startup IO",
    jobTitle: "CEO",
    department: "Direction",
    nicknames: ["Soph"],
    birthday: { day: 22, month: 4, year: 1985 },
    notes: "Rencontrée au salon VivaTech — intéressée par l'intégration webhooks.",
    addresses: [
      {
        street: "55 rue du Faubourg Saint-Honoré",
        city: "Paris",
        region: "Île-de-France",
        postalCode: "75008",
        country: "France",
        label: "work",
      },
    ],
    socialProfiles: [{ value: "https://linkedin.com/in/sophie-morel", label: "LinkedIn" }],
    interactionCount: 12,
  }),
  c({
    firstName: "Amadou",
    lastName: "Diop",
    emails: [{ value: "amadou.diop@outlook.com", label: "personal" }],
    phones: [{ value: "+221 77 456 78 90", label: "mobile" }],
    company: "Dakar Startup Hub",
    jobTitle: "Program Manager",
    addresses: [
      {
        street: "15 Avenue Cheikh Anta Diop",
        city: "Dakar",
        region: "Dakar",
        postalCode: "18524",
        country: "Sénégal",
        label: "work",
      },
    ],
    isOtherContact: true,
    interactionCount: 7,
  }),
  c({
    firstName: "Hélène",
    lastName: "Marchand",
    emails: [
      { value: "helene.marchand@lyon-tech.fr", label: "work" },
      { value: "helene.m@gmail.com", label: "personal" },
    ],
    phones: [{ value: "+33 6 44 55 66 77", label: "mobile" }],
    company: "Lyon Tech",
    department: "Ingénierie",
    jobTitle: "Lead Backend",
    nicknames: ["Hélène M."],
    labels: ["Tech", "Partenaire"],
    birthday: { day: 8, month: 2, year: 1990 },
    addresses: [
      {
        street: "24 rue de la République",
        city: "Lyon",
        region: "Auvergne-Rhône-Alpes",
        postalCode: "69002",
        country: "France",
        label: "work",
      },
    ],
    socialProfiles: [{ value: "https://linkedin.com/in/helene-marchand", label: "LinkedIn" }],
    interactionCount: 38,
  }),
  c({
    firstName: "Thomas",
    lastName: "Giraud",
    emails: [{ value: "thomas.giraud@toulouse-data.fr", label: "work" }],
    phones: [{ value: "+33 6 21 43 65 87", label: "mobile" }],
    company: "Toulouse Data",
    jobTitle: "Data Engineer",
    department: "Analytics",
    addresses: [
      {
        street: "8 allées Jean Jaurès",
        city: "Toulouse",
        region: "Occitanie",
        postalCode: "31000",
        country: "France",
        label: "work",
      },
    ],
    notes: "Spécialiste pipelines ETL — contact pour le projet BI.",
  }),
  c({
    firstName: "Émilie",
    lastName: "Rousseau",
    emails: [{ value: "emilie.rousseau@gmail.com", label: "personal" }],
    phones: [{ value: "+33 6 88 77 66 55", label: "mobile" }],
    nicknames: ["Mimi"],
    birthday: { day: 17, month: 9, year: 1993 },
    labels: ["Amis"],
    addresses: [
      {
        street: "14 rue Sainte-Catherine",
        city: "Bordeaux",
        region: "Nouvelle-Aquitaine",
        postalCode: "33000",
        country: "France",
        label: "home",
      },
    ],
    interactionCount: 22,
  }),
  c({
    firstName: "Florian",
    lastName: "Meyer",
    emails: [
      { value: "florian.meyer@gmx.de", label: "personal" },
      { value: "f.meyer@berlin-dev.io", label: "work" },
    ],
    phones: [{ value: "+49 170 1234567", label: "mobile" }],
    company: "Berlin Dev",
    jobTitle: "DevOps Engineer",
    department: "Infrastructure",
    addresses: [
      {
        street: "Torstraße 102",
        city: "Berlin",
        region: "Berlin",
        postalCode: "10119",
        country: "Germany",
        label: "work",
      },
    ],
    socialProfiles: [
      { value: "https://linkedin.com/in/florian-meyer", label: "LinkedIn" },
      { value: "https://x.com/florian_meyer", label: "X" },
    ],
    interactionCount: 15,
  }),
  c({
    firstName: "Javier",
    lastName: "Muñoz",
    emails: [{ value: "javier.munoz@gmail.com", label: "personal" }],
    phones: [{ value: "+34 612 345 678", label: "mobile" }],
    company: "Telefónica",
    jobTitle: "Data Scientist",
    addresses: [
      {
        street: "Calle de Alcalá 48",
        city: "Madrid",
        region: "Comunidad de Madrid",
        postalCode: "28014",
        country: "Spain",
        label: "work",
      },
    ],
    labels: ["Conférence"],
    isOtherContact: true,
  }),
  c({
    firstName: "Chloé",
    lastName: "Tremblay",
    emails: [
      { value: "chloe.tremblay@ultimail.ca", label: "work" },
      { value: "chloe.t@gmail.com", label: "personal" },
    ],
    phones: [
      { value: "+1 514 555 0198", label: "mobile" },
      { value: "+1 514 555 0100", label: "work" },
    ],
    company: "Ultimail Canada",
    department: "Support",
    jobTitle: "Customer Success",
    nicknames: ["Chlo"],
    birthday: { day: 5, month: 12, year: 1994 },
    addresses: [
      {
        street: "1010 Rue Sainte-Catherine Ouest",
        city: "Montréal",
        region: "Québec",
        postalCode: "H3B 1G1",
        country: "Canada",
        label: "work",
      },
      {
        street: "4525 Avenue du Parc",
        city: "Montréal",
        region: "Québec",
        postalCode: "H2V 4E7",
        country: "Canada",
        label: "home",
      },
    ],
    socialProfiles: [{ value: "https://linkedin.com/in/chloe-tremblay", label: "LinkedIn" }],
    interactionCount: 41,
  }),
  c({
    firstName: "Hana",
    lastName: "Yamamoto",
    emails: [{ value: "hana.yamamoto@gmail.com", label: "personal" }],
    phones: [{ value: "+81 90 1234 5678", label: "mobile" }],
    company: "Nippon Design Co.",
    jobTitle: "UX Researcher",
    addresses: [
      {
        street: "2-8-1 Nishi-Shinjuku",
        city: "Tokyo",
        region: "Tokyo",
        postalCode: "163-8001",
        country: "Japan",
        label: "work",
      },
    ],
    notes: "Collaboration design system — fuseau UTC+9.",
    labels: ["Design"],
  }),
  c({
    firstName: "Priya",
    lastName: "Sharma",
    emails: [
      { value: "priya.sharma@outlook.com", label: "personal" },
      { value: "priya@infosys-partner.in", label: "work" },
    ],
    phones: [{ value: "+91 98765 43210", label: "mobile" }],
    company: "Infosys",
    department: "Delivery",
    jobTitle: "Team Lead",
    addresses: [
      {
        street: "44 MG Road",
        city: "Bengaluru",
        region: "Karnataka",
        postalCode: "560001",
        country: "India",
        label: "work",
      },
    ],
    socialProfiles: [{ value: "https://linkedin.com/in/priya-sharma", label: "LinkedIn" }],
    interactionCount: 26,
  }),
  c({
    firstName: "Augustin",
    lastName: "Ferrand",
    emails: [{ value: "augustin.ferrand@proton.me", label: "personal" }],
    phones: [],
    isOtherContact: true,
    notes: "Ajouté automatiquement depuis un mail reçu.",
  }),
  c({
    firstName: "Nadia",
    lastName: "Haddad",
    emails: [{ value: "nadia.haddad@gmail.com", label: "personal" }],
    phones: [{ value: "+33 6 43 21 09 87", label: "mobile" }],
    company: "Mistral AI",
    jobTitle: "Research Engineer",
    department: "R&D",
    labels: ["IA"],
    addresses: [
      {
        street: "15 rue des Halles",
        city: "Paris",
        region: "Île-de-France",
        postalCode: "75001",
        country: "France",
        label: "work",
      },
    ],
    socialProfiles: [{ value: "https://x.com/nadia_haddad", label: "X" }],
    interactionCount: 9,
  }),
  c({
    firstName: "Vincent",
    lastName: "Morel",
    emails: [
      { value: "vincent.morel@gmail.com", label: "personal" },
      { value: "vincent.morel@blablacar.com", label: "work" },
    ],
    phones: [{ value: "+33 6 65 78 90 12", label: "mobile" }],
    company: "BlaBlaCar",
    jobTitle: "VP Engineering",
    department: "Platform",
    nicknames: ["Vince"],
    birthday: { day: 12, month: 4, year: 1987 },
    addresses: [
      {
        street: "84 avenue de la République",
        city: "Paris",
        region: "Île-de-France",
        postalCode: "75011",
        country: "France",
        label: "work",
      },
    ],
    socialProfiles: [
      { value: "https://linkedin.com/in/vincent-morel", label: "LinkedIn" },
    ],
    interactionCount: 42,
  }),
  c({
    firstName: "Fatou",
    lastName: "Sow",
    emails: [{ value: "fatou.sow@orange.sn", label: "work" }],
    phones: [{ value: "+221 70 123 45 67", label: "mobile" }],
    company: "Orange Sénégal",
    jobTitle: "Account Manager",
    addresses: [
      {
        street: "Km 8 Route de Ouakam",
        city: "Dakar",
        region: "Dakar",
        postalCode: "18524",
        country: "Sénégal",
        label: "work",
      },
    ],
    labels: ["Partenaire"],
    interactionCount: 14,
  }),
  c({
    firstName: "Lucie",
    lastName: "Simon",
    emails: [{ value: "lucie.simon@proton.me", label: "personal" }],
    phones: [{ value: "+33 6 67 89 01 23", label: "mobile" }],
    nicknames: ["Lu"],
    birthday: { day: 28, month: 2, year: 1997 },
    labels: ["Famille"],
    addresses: [
      {
        street: "6 place du Capitole",
        city: "Toulouse",
        region: "Occitanie",
        postalCode: "31000",
        country: "France",
        label: "home",
      },
    ],
  }),
  c({
    firstName: "Kevin",
    lastName: "Park",
    emails: [{ value: "kevin.park@gmail.com", label: "personal" }],
    phones: [{ value: "+82 10 1234 5678", label: "mobile" }],
    company: "Samsung",
    jobTitle: "Frontend Engineer",
    department: "Mobile",
    addresses: [
      {
        street: "129 Samsung-ro",
        city: "Suwon",
        region: "Gyeonggi",
        postalCode: "16677",
        country: "South Korea",
        label: "work",
      },
    ],
    socialProfiles: [{ value: "https://linkedin.com/in/kevin-park", label: "LinkedIn" }],
  }),
  c({
    firstName: "Manon",
    lastName: "Leroy",
    emails: [
      { value: "manon.leroy@outlook.fr", label: "personal" },
      { value: "manon.leroy@ovhcloud.com", label: "work" },
    ],
    phones: [{ value: "+33 6 32 10 98 76", label: "mobile" }],
    company: "OVHcloud",
    jobTitle: "SRE",
    department: "Cloud Ops",
    notes: "Contact infra — escalade incidents P1.",
    addresses: [
      {
        street: "2 rue Kellermann",
        city: "Roubaix",
        region: "Hauts-de-France",
        postalCode: "59100",
        country: "France",
        label: "work",
      },
    ],
    interactionCount: 33,
  }),
  c({
    firstName: "Rachid",
    lastName: "Ouali",
    emails: [{ value: "rachid.ouali@yahoo.fr", label: "personal" }],
    phones: [{ value: "+33 6 87 65 43 21", label: "mobile" }],
    company: "Freelance",
    jobTitle: "Photographe",
    addresses: [
      {
        street: "23 cours Mirabeau",
        city: "Aix-en-Provence",
        region: "Provence-Alpes-Côte d'Azur",
        postalCode: "13100",
        country: "France",
        label: "home",
      },
    ],
    labels: ["Créatif"],
  }),
  c({
    firstName: "Elena",
    lastName: "Kuznetsova",
    emails: [{ value: "elena.kuznetsova@mail.ru", label: "personal" }],
    phones: [{ value: "+7 916 123 45 67", label: "mobile" }],
    company: "Yandex",
    jobTitle: "ML Engineer",
    addresses: [
      {
        street: "16 Leo Tolstoy Street",
        city: "Moscow",
        region: "Moscow",
        postalCode: "119021",
        country: "Russia",
        label: "work",
      },
    ],
    interactionCount: 6,
  }),
  c({
    firstName: "Youssef",
    lastName: "Alaoui",
    emails: [
      { value: "youssef.alaoui@outlook.com", label: "personal" },
      { value: "y.alaoui@ram.ma", label: "work" },
    ],
    phones: [{ value: "+212 6 45 67 89 01", label: "mobile" }],
    company: "Royal Air Maroc",
    jobTitle: "IT Manager",
    department: "Systèmes",
    addresses: [
      {
        street: "Aéroport Mohammed V",
        city: "Casablanca",
        region: "Casablanca-Settat",
        postalCode: "20000",
        country: "Morocco",
        label: "work",
      },
    ],
    socialProfiles: [{ value: "https://linkedin.com/in/youssef-alaoui", label: "LinkedIn" }],
    interactionCount: 11,
  }),
  c({
    firstName: "Charlotte",
    lastName: "Martin",
    emails: [{ value: "charlotte.martin@gmail.com", label: "personal" }],
    phones: [{ value: "+33 6 22 11 00 99", label: "mobile" }],
    birthday: { day: 5, month: 11, year: 1995 },
    nicknames: ["Cha"],
    addresses: [
      {
        street: "9 rue de la République",
        city: "Lyon",
        region: "Auvergne-Rhône-Alpes",
        postalCode: "69001",
        country: "France",
        label: "home",
      },
    ],
    labels: ["Amis"],
    interactionCount: 18,
  }),
  c({
    firstName: "Gabriel",
    lastName: "Santos",
    emails: [{ value: "gabriel.santos@outlook.com", label: "personal" }],
    phones: [{ value: "+55 11 98765 4321", label: "mobile" }],
    company: "Nubank",
    jobTitle: "Product Designer",
    addresses: [
      {
        street: "Rua Capote Valente 39",
        city: "São Paulo",
        region: "SP",
        postalCode: "05409-000",
        country: "Brazil",
        label: "work",
      },
    ],
    socialProfiles: [
      { value: "https://linkedin.com/in/gabriel-santos", label: "LinkedIn" },
      { value: "https://x.com/gabriel_santos", label: "X" },
    ],
  }),
  c({
    firstName: "Inès",
    lastName: "Belhadj",
    emails: [{ value: "ines.belhadj@gmail.com", label: "personal" }],
    phones: [],
    company: "Doctolib",
    jobTitle: "iOS Developer",
    department: "Mobile",
    notes: "Ancienne collègue — recommandation stage.",
    addresses: [
      {
        street: "54 quai de la Rapée",
        city: "Paris",
        region: "Île-de-France",
        postalCode: "75012",
        country: "France",
        label: "work",
      },
    ],
  }),
  c({
    firstName: "William",
    lastName: "Hartmann",
    emails: [{ value: "william.hartmann@gmx.de", label: "personal" }],
    phones: [{ value: "+49 160 9876543", label: "mobile" }],
    company: "Bosch",
    jobTitle: "Embedded Engineer",
    addresses: [
      {
        street: "Robert-Bosch-Platz 1",
        city: "Stuttgart",
        region: "Baden-Württemberg",
        postalCode: "70839",
        country: "Germany",
        label: "work",
      },
    ],
    interactionCount: 4,
  }),
  c({
    firstName: "Sandra",
    lastName: "Oliveira",
    emails: [{ value: "sandra.oliveira@outlook.com", label: "personal" }],
    phones: [{ value: "+351 912 345 678", label: "mobile" }],
    company: "Farfetch",
    jobTitle: "QA Lead",
    addresses: [
      {
        street: "Rua do Ouro 240",
        city: "Lisbon",
        region: "Lisboa",
        postalCode: "1100-063",
        country: "Portugal",
        label: "work",
      },
    ],
    labels: ["QA"],
    birthday: { day: 30, month: 6, year: 1990 },
  }),
  c({
    firstName: "Mehdi",
    lastName: "Bouaziz",
    emails: [{ value: "mehdi.bouaziz@outlook.com", label: "personal" }],
    phones: [{ value: "+216 55 123 456", label: "mobile" }],
    company: "Sofrecom",
    jobTitle: "Architecte solutions",
    department: "Consulting",
    addresses: [
      {
        street: "Les Berges du Lac",
        city: "Tunis",
        region: "Tunis",
        postalCode: "1053",
        country: "Tunisia",
        label: "work",
      },
    ],
    socialProfiles: [{ value: "https://linkedin.com/in/mehdi-bouaziz", label: "LinkedIn" }],
    interactionCount: 8,
  }),
].sort((a, b) => {
  const nameA = `${a.firstName} ${a.lastName}`.toLowerCase()
  const nameB = `${b.firstName} ${b.lastName}`.toLowerCase()
  return nameA.localeCompare(nameB)
})

export const DEMO_FULL_CONTACTS: FullContact[] = applyDemoAvatars(RAW_DEMO_CONTACTS)

export function createInitialDemoContacts(): FullContact[] {
  return [...DEMO_FULL_CONTACTS]
}
