// lib/demo-data.ts
/**
 * Système de données de démo pour l'espace paie CDDU
 * 
 * Ce fichier contient toutes les données fictives réalistes
 * pour démontrer les fonctionnalités de l'application
 */

export interface DemoUser {
  id: string;
  email: string;
  display_name: string;
  first_name: string;
}

export interface DemoOrganization {
  id: string;
  name: string;
  api_name: string;
  siret?: string;
  address?: string;
}

export interface DemoEmployee {
  id: string;
  nom: string;
  prenom: string;
  email: string;
  telephone?: string;
  date_naissance?: string;
  securite_sociale?: string;
  adresse?: string;
}

export interface DemoContract {
  id: string;
  reference: string;
  salarie_nom: string;
  salarie_id: string;
  production: string;
  profession: string;
  date_debut: string;
  date_fin: string;
  etat: "pre-demande" | "Reçue" | "envoye" | "signe" | "modification" | "traitee" | "en_cours";
  is_multi_mois?: boolean;
  regime: "CDDU_MONO" | "CDDU_MULTI" | "RG";
  salaire_brut?: number;
  heures_semaine?: number;
}

export interface DemoPayslip {
  id: string;
  contrat_id: string;
  salarie_nom: string;
  periode: string; // "2024-01"
  salaire_brut: number;
  salaire_net: number;
  charges_sociales: number;
  heures_travaillees: number;
  statut: "en_cours" | "valide" | "paye";
}

// Données de démo
export const DEMO_USER: DemoUser = {
  id: "demo-user-001",
  email: "demo@odentas.fr",
  display_name: "Utilisateur Démo",
  first_name: "Utilisateur"
};

export const DEMO_ORGANIZATION: DemoOrganization = {
  id: "demo-org-001",
  name: "Compagnie Théâtrale Demo",
  api_name: "compagnie-theatrale-demo",
  siret: "12345678901234",
  address: "123 Rue de la Scène, 75001 Paris"
};

export const DEMO_EMPLOYEES: DemoEmployee[] = [
  {
    id: "emp-001",
    nom: "MARTIN",
    prenom: "Alice",
    email: "alice.martin@example.com",
    telephone: "0123456789",
    date_naissance: "1992-05-15",
    securite_sociale: "1920515123456",
    adresse: "45 Rue des Artistes, 75018 Paris"
  },
  {
    id: "emp-002", 
    nom: "DUBOIS",
    prenom: "Pierre",
    email: "pierre.dubois@example.com",
    telephone: "0987654321",
    date_naissance: "1988-11-23",
    securite_sociale: "1881123654321",
    adresse: "67 Avenue du Spectacle, 69001 Lyon"
  },
  {
    id: "emp-003",
    nom: "LEROY",
    prenom: "Sophie",
    email: "sophie.leroy@example.com",
    telephone: "0145678932",
    date_naissance: "1995-03-08",
    securite_sociale: "2950308789123",
    adresse: "89 Boulevard des Comédiens, 13001 Marseille"
  },
  {
    id: "emp-004",
    nom: "BERNARD",
    prenom: "Julien",
    email: "julien.bernard@example.com",
    telephone: "0567891234",
    date_naissance: "1990-07-12",
    securite_sociale: "1900712456789",
    adresse: "12 Impasse de la Danse, 31000 Toulouse"
  },
  {
    id: "emp-005",
    nom: "PETIT",
    prenom: "Marie",
    email: "marie.petit@example.com",
    telephone: "0234567891",
    date_naissance: "1993-12-03",
    securite_sociale: "2931203567891",
    adresse: "34 Rue de la Musique, 44000 Nantes"
  }
];

export const DEMO_CONTRACTS: DemoContract[] = [
  {
    id: "demo-cont-001",
    reference: "CDDU-2024-001",
    salarie_nom: "MARTIN Alice",
    salarie_id: "emp-001",
    production: "Les Misérables - Tournée 2024",
    profession: "04201 - Comédien",
    date_debut: "2024-01-15",
    date_fin: "2024-06-30",
    etat: "en_cours",
    regime: "CDDU_MULTI",
    is_multi_mois: true,
    salaire_brut: 3200,
    heures_semaine: 39
  },
  {
    id: "demo-cont-002",
    reference: "CDDU-2024-002", 
    salarie_nom: "DUBOIS Pierre",
    salarie_id: "emp-002",
    production: "Le Cid - Avignon 2024",
    profession: "04202 - Metteur en scène",
    date_debut: "2024-07-05",
    date_fin: "2024-07-28",
    etat: "signe",
    regime: "CDDU_MONO",
    salaire_brut: 4500,
    heures_semaine: 45
  },
  {
    id: "demo-cont-003",
    reference: "CDDU-2024-003",
    salarie_nom: "LEROY Sophie", 
    salarie_id: "emp-003",
    production: "Ballet Moderne - Saison 2024",
    profession: "04301 - Danseur",
    date_debut: "2024-09-01",
    date_fin: "2024-12-20",
    etat: "en_cours",
    regime: "CDDU_MULTI",
    is_multi_mois: true,
    salaire_brut: 2800,
    heures_semaine: 35
  },
  {
    id: "demo-cont-004",
    reference: "CDDU-2024-004",
    salarie_nom: "BERNARD Julien",
    salarie_id: "emp-004", 
    production: "Concert Jazz Festival",
    profession: "04401 - Musicien",
    date_debut: "2024-06-15",
    date_fin: "2024-06-17",
    etat: "traitee",
    regime: "CDDU_MONO",
    salaire_brut: 1200,
    heures_semaine: 20
  },
  {
    id: "demo-cont-005",
    reference: "CDDU-2024-005",
    salarie_nom: "PETIT Marie",
    salarie_id: "emp-005",
    production: "Opéra Carmen - Tournée",
    profession: "04501 - Choriste",
    date_debut: "2024-03-01",
    date_fin: "2024-05-31",
    etat: "en_cours",
    regime: "CDDU_MULTI",
    is_multi_mois: true,
    salaire_brut: 2400,
    heures_semaine: 32
  },
  {
    id: "demo-cont-006",
    reference: "CDDU-2024-006",
    salarie_nom: "MARTIN Alice",
    salarie_id: "emp-001",
    production: "Atelier Théâtre Jeunesse",
    profession: "04203 - Animateur culturel",
    date_debut: "2024-10-01",
    date_fin: "2024-10-15",
    etat: "envoye",
    regime: "CDDU_MONO",
    salaire_brut: 1800,
    heures_semaine: 25
  },
  {
    id: "demo-cont-007",
    reference: "CDDU-2024-007",
    salarie_nom: "DUBOIS Pierre",
    salarie_id: "emp-002",
    production: "Film Documentaire Art",
    profession: "04204 - Réalisateur",
    date_debut: "2024-11-15",
    date_fin: "2024-12-15",
    etat: "pre-demande",
    regime: "CDDU_MONO",
    salaire_brut: 5000,
    heures_semaine: 40
  }
];

export const DEMO_PAYSLIPS: DemoPayslip[] = [
  // MARTIN Alice - Les Misérables
  {
    id: "pay-001",
    contrat_id: "demo-cont-001",
    salarie_nom: "MARTIN Alice",
    periode: "2024-01",
    salaire_brut: 3200,
    salaire_net: 2496,
    charges_sociales: 704,
    heures_travaillees: 169,
    statut: "paye"
  },
  {
    id: "pay-002", 
    contrat_id: "demo-cont-001",
    salarie_nom: "MARTIN Alice",
    periode: "2024-02",
    salaire_brut: 3200,
    salaire_net: 2496,
    charges_sociales: 704,
    heures_travaillees: 161,
    statut: "paye"
  },
  {
    id: "pay-003",
    contrat_id: "demo-cont-001", 
    salarie_nom: "MARTIN Alice",
    periode: "2024-03",
    salaire_brut: 3200,
    salaire_net: 2496,
    charges_sociales: 704,
    heures_travaillees: 172,
    statut: "paye"
  },
  // DUBOIS Pierre - Le Cid
  {
    id: "pay-004",
    contrat_id: "demo-cont-002",
    salarie_nom: "DUBOIS Pierre", 
    periode: "2024-07",
    salaire_brut: 4500,
    salaire_net: 3510,
    charges_sociales: 990,
    heures_travaillees: 180,
    statut: "paye"
  },
  // LEROY Sophie - Ballet
  {
    id: "pay-005",
    contrat_id: "demo-cont-003",
    salarie_nom: "LEROY Sophie",
    periode: "2024-09",
    salaire_brut: 2800,
    salaire_net: 2184,
    charges_sociales: 616,
    heures_travaillees: 151,
    statut: "paye"
  },
  {
    id: "pay-006",
    contrat_id: "demo-cont-003", 
    salarie_nom: "LEROY Sophie",
    periode: "2024-10",
    salaire_brut: 2800,
    salaire_net: 2184,
    charges_sociales: 616,
    heures_travaillees: 156,
    statut: "valide"
  },
  // BERNARD Julien - Jazz Festival
  {
    id: "pay-007",
    contrat_id: "demo-cont-004",
    salarie_nom: "BERNARD Julien",
    periode: "2024-06", 
    salaire_brut: 1200,
    salaire_net: 936,
    charges_sociales: 264,
    heures_travaillees: 60,
    statut: "paye"
  },
  // PETIT Marie - Opéra Carmen
  {
    id: "pay-008",
    contrat_id: "demo-cont-005",
    salarie_nom: "PETIT Marie",
    periode: "2024-03",
    salaire_brut: 2400,
    salaire_net: 1872,
    charges_sociales: 528,
    heures_travaillees: 138,
    statut: "paye"
  },
  {
    id: "pay-009",
    contrat_id: "demo-cont-005",
    salarie_nom: "PETIT Marie", 
    periode: "2024-04",
    salaire_brut: 2400,
    salaire_net: 1872,
    charges_sociales: 528,
    heures_travaillees: 142,
    statut: "paye"
  },
  {
    id: "pay-010",
    contrat_id: "demo-cont-005",
    salarie_nom: "PETIT Marie",
    periode: "2024-05",
    salaire_brut: 2400,
    salaire_net: 1872,
    charges_sociales: 528,
    heures_travaillees: 145,
    statut: "en_cours"
  }
];

/**
 * Recherche dans les données de démo
 */
export function searchDemoData(query: string): Array<{
  type: 'contract' | 'employee' | 'payslip';
  id: string;
  title: string;
  subtitle: string;
}> {
  const results: Array<{
    type: 'contract' | 'employee' | 'payslip';
    id: string; 
    title: string;
    subtitle: string;
  }> = [];

  const searchTerm = query.toLowerCase();

  // Recherche dans les contrats
  DEMO_CONTRACTS.forEach(contract => {
    if (
      contract.reference.toLowerCase().includes(searchTerm) ||
      contract.salarie_nom.toLowerCase().includes(searchTerm) ||
      contract.production.toLowerCase().includes(searchTerm) ||
      contract.profession.toLowerCase().includes(searchTerm)
    ) {
      results.push({
        type: 'contract',
        id: contract.id,
        title: `${contract.reference} - ${contract.salarie_nom}`,
        subtitle: contract.production
      });
    }
  });

  // Recherche dans les employés
  DEMO_EMPLOYEES.forEach(employee => {
    if (
      `${employee.nom} ${employee.prenom}`.toLowerCase().includes(searchTerm) ||
      employee.email.toLowerCase().includes(searchTerm)
    ) {
      results.push({
        type: 'employee',
        id: employee.id,
        title: `${employee.nom} ${employee.prenom}`,
        subtitle: employee.email
      });
    }
  });

  // Recherche dans les bulletins
  DEMO_PAYSLIPS.forEach(payslip => {
    if (
      payslip.salarie_nom.toLowerCase().includes(searchTerm) ||
      payslip.periode.includes(searchTerm)
    ) {
      results.push({
        type: 'payslip',
        id: payslip.id,
        title: `Bulletin ${payslip.periode} - ${payslip.salarie_nom}`,
        subtitle: `${payslip.salaire_net}€ net`
      });
    }
  });

  return results.slice(0, 10); // Limiter à 10 résultats
}