import pandas as pd
from django.db import models
from gestion_employe.models import Employe

class Conge(models.Model):
    """Modèle de création des congés"""
    TYPE_CHOICES = [
        # ('maladie', 'Maladie'),
        ('conge_annuel', 'Conge Annuel'),
        # ('conge_maternite', 'Conge Maternité'),
        # ('conge_mariage', 'Conge Mariage'),
        # ('conge_naissance', 'Conge de Naissance'),
        # ('conge_deces_proche', 'Conge de décès d\'un proche'),
        # ('conge_mariage_proche', 'Conge de mariage d\'un proche'),
        # ('autre', 'Autre'),
    ]
    
    employe = models.ForeignKey(
        Employe, 
        on_delete=models.CASCADE,
        related_name="employe"
    )
    date_debut = models.DateField(verbose_name='Date de Début')
    date_fin = models.DateField(verbose_name='Date de Fin')
    type = models.CharField(max_length=100, choices=TYPE_CHOICES, verbose_name='Type de Congé')
    date_demande = models.DateField(auto_now_add=True, verbose_name="Date de Demande")
    validation_hierarchique = models.BooleanField(default=None, null=True)
    validation_direction = models.BooleanField(default=None, null=True)
   
    motif_refus = models.TextField(blank=True, null=True)     

    @property
    def nombre_jours(self):
        if self.date_debut and self.date_fin:
            jours = pd.bdate_range(start=self.date_debut, end=self.date_fin)
            return len(jours)