from django.db import models
from .programs import Program
from .applicants import Applicant
from .teams import Team

class Registration(models.Model):
    STATUS_CHOICES = [
        ('PENDING', 'Pending'),
        ('APPROVED', 'Approved'),
        ('REJECTED', 'Rejected'),
        ('CDE',"CDE"),
    ]

    TYPE_CHOICES = [
        ('INDIVIDUAL', 'Individuelle'),
        ('TEAM', 'Équipe'),
    ]

    registration_type = models.CharField(max_length=20, choices=TYPE_CHOICES, default='INDIVIDUAL', verbose_name="Type d'inscription")
    program = models.ForeignKey(Program, on_delete=models.RESTRICT, related_name='registrations', null=True, blank=True)
    applicant = models.ForeignKey(Applicant, on_delete=models.RESTRICT, related_name='registrations', null=True, blank=True)
    team = models.ForeignKey(Team, on_delete=models.RESTRICT, related_name='registrations', null=True, blank=True)
    project = models.ForeignKey('Project', on_delete=models.RESTRICT, null=True, blank=True, related_name='registrations')
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='PENDING')
    role = models.CharField(max_length=100, blank=True, null=True, verbose_name="Rôle")
    motivation = models.TextField(blank=True, null=True, verbose_name="Motivation")
    application_date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        program_title = self.program.title if self.program else "Générale"
        registrant = self.applicant if self.applicant else self.team
        return f"Inscription: {registrant} -> {program_title}"
