from django.db import models

class ContactMessage(models.Model):
    OBJET_CHOICES = [
        ("Demande d'information", "Demande d'information"),
        ("Inscription", "Inscription"),
        ("Stage", "Stage"),
        ("Autre", "Autre"),
    ]

    nom = models.CharField(max_length=100)
    email = models.EmailField()
    telephone = models.CharField(max_length=20, blank=True, null=True)
    objet = models.CharField(max_length=50, choices=OBJET_CHOICES)
    message = models.TextField()
    date_envoi = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"Message de {self.nom} - {self.objet}"

class Candidature(models.Model):
    SEXE_CHOICES = [
        ('M', 'Masculin'),
        ('F', 'Féminin'),
    ]
    
    TYPE_FORMATION_CHOICES = [
        ('BTS', 'BTS'),
        ('LICENCE', 'Licence'),
        ('MASTER', 'Master'),
        ('PREPA', 'Classe préparatoire'),
    ]
    
    MODE_ETUDE_CHOICES = [
        ('JOUR', 'Jour'),
        ('SOIR', 'Soirée'),
        ('WEEKEND', 'Week-end'),
    ]

    # Étape 1 : Informations personnelles
    nom = models.CharField(max_length=100)
    prenoms = models.CharField(max_length=200)
    sexe = models.CharField(max_length=1, choices=SEXE_CHOICES)
    date_naissance = models.DateField()
    lieu_naissance = models.CharField(max_length=100)
    nationalite = models.CharField(max_length=100)
    photo_identite = models.FileField(upload_to='candidatures/photos/')
    telephone = models.CharField(max_length=20)
    whatsapp = models.CharField(max_length=20, blank=True, null=True)
    email = models.EmailField()
    adresse_complete = models.TextField()
    ville_pays = models.CharField(max_length=200)

    # Étape 2 : Informations académiques
    dernier_diplome = models.CharField(max_length=100)
    serie_bac = models.CharField(max_length=50)
    annee_obtention = models.IntegerField()
    etablissement_frequente = models.CharField(max_length=200)
    moyenne_obtenue = models.DecimalField(max_digits=4, decimal_places=2)
    niveau_actuel_etude = models.CharField(max_length=100)

    # Étape 3 : Choix de formation
    type_formation = models.CharField(max_length=20, choices=TYPE_FORMATION_CHOICES)
    filiere_choisie = models.CharField(max_length=100)
    deuxieme_choix_filiere = models.CharField(max_length=100, blank=True, null=True)
    mode_etude = models.CharField(max_length=20, choices=MODE_ETUDE_CHOICES)

    # Étape 4 : Documents
    bac_releve = models.FileField(upload_to='candidatures/documents/')
    acte_naissance = models.FileField(upload_to='candidatures/documents/')
    certificat_nationalite = models.FileField(upload_to='candidatures/documents/', blank=True, null=True)
    cv = models.FileField(upload_to='candidatures/documents/', blank=True, null=True)
    lettre_motivation = models.FileField(upload_to='candidatures/documents/')

    # Étape 5 : Contact d'urgence
    parent_nom = models.CharField(max_length=100)
    parent_profession = models.CharField(max_length=100)
    parent_telephone = models.CharField(max_length=20)
    parent_relation = models.CharField(max_length=100)

    # Étape 6 : Informations complémentaires
    motivation = models.TextField()
    experience_professionnelle = models.TextField(blank=True, null=True)
    projet_professionnel = models.TextField()

    # Étape 7 : Validation
    certifie_exactitude = models.BooleanField(default=False)
    date_soumission = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"Candidature de {self.nom} {self.prenoms} - {self.type_formation}"
