from django.db import models

# Create your models here.


class Kart(models.Model):
    # Name of the team
    name = models.CharField(max_length=30, default=None, blank=True, null=True)
    autonomy = models.IntegerField()
    comment = models.CharField(max_length=256, default=None, blank=True, null=True)

    def __str__(self):
        return self.name


class Driver(models.Model):
    kart = models.ForeignKey(Kart, related_name='drivers', on_delete=models.CASCADE)
    short_name = models.CharField(max_length=10, default=None, blank=True, null=True)
    first_name = models.CharField(max_length=30, default=None, blank=True, null=True)
    last_name = models.CharField(max_length=30, default=None, blank=True, null=True)
    order = models.IntegerField()
    ref_time = models.IntegerField()

    class Meta:
        ordering = ['order']

    def __str__(self):
        return self.kart.__str__() + " : " + self.first_name + " " + self.last_name


class Params(models.Model):
    # Name of the pilot
    autonomy = models.IntegerField()
    default_relay = models.IntegerField()
    stand_minimum_time = models.IntegerField()
    comment = models.CharField(max_length=250)


class Relay(models.Model):
    # Fk driver
    driver = models.ForeignKey(Driver, on_delete=models.CASCADE)
    # Fk kart
    kart = models.ForeignKey(Kart, on_delete=models.CASCADE)
    # Starting timestamp for the relay
    relay_start = models.DateTimeField()
    # ending timestamp for the relay
    relay_end = models.DateTimeField(default=None, blank=True, null=True)
    # Does the previous pilot refuel
    has_refuel = models.BooleanField(default=False)
    # Average chrono for the pulot on this relay
    driver_chrono = models.IntegerField(default=None, blank=True, null=True)
    # ending timestamp for the relay
    relay_autonomy = models.IntegerField(default=None, blank=True, null=True)
    # comment the relay
    comment = models.CharField(max_length=256, default=None, blank=True, null=True)

    class Meta:
        ordering = ['relay_start']
