from django.db import models
from django.contrib import admin
from django.contrib.auth.models import User as DjangoUser

ALKATOR_CHOICES = (
    (1, "Alkátor"),
    (2, "Alkátor light"),
    (3, "Nealkátor"),
)

ALKATOR_CLASSES = (
    (1, "Jaro 2024 Sobkovice"),
    (2, "Podzim 2024 Studené"),
    (3, "Jaro 2025 Dolní Čermná")
)

ALKATOR_CHOICES_DICT = {
    alkator_choice[0]: alkator_choice[1]
    for alkator_choice in ALKATOR_CHOICES
}

ALKATOR_CLASSES_DICT = {
    alkator_class[0]: alkator_class[1]
    for alkator_class in ALKATOR_CLASSES
}

class User(models.Model):
    first_name = models.CharField(max_length=120)
    last_name = models.CharField(max_length=120)
    address = models.CharField(max_length=255, null=True, blank=True)
    email = models.EmailField(max_length=120, null=True, blank=True)
    phone = models.CharField(max_length=120, null=True, blank=True)
    date_of_birth = models.DateField(null=True, blank=True)
    register_date = models.DateTimeField(auto_now=True)
    duration = models.DurationField(null=True, blank=True)
    starting_number = models.IntegerField(null=True, blank=True)
    alkator_category = models.IntegerField(choices=ALKATOR_CHOICES, default=1)
    alkator_class = models.IntegerField(choices=ALKATOR_CLASSES)
    trans_id = models.CharField(null=True, blank=True, max_length=120)
    price = models.IntegerField(default=690)
    paid = models.BooleanField(default=False)
    invoice_id = models.IntegerField(null=True, blank=True, unique=True)

    def __str__(self):
        return f"<User {self.starting_number} {self.first_name} {self.last_name} {self.email} {self.duration} {ALKATOR_CHOICES_DICT[self.alkator_category]} {ALKATOR_CLASSES_DICT[self.alkator_class]} {self.paid}>"


class Profile(models.Model):
    user = models.OneToOneField(DjangoUser, related_name='profile', on_delete=models.CASCADE)
    first_name = models.CharField(max_length=120)
    last_name = models.CharField(max_length=120)
    address = models.CharField(max_length=255, null=True, blank=True)


class Racer(models.Model):
    profile = models.ForeignKey(Profile, related_name='racers', on_delete=models.CASCADE)
    first_name = models.CharField(max_length=120)
    last_name = models.CharField(max_length=120)
    email = models.EmailField(max_length=120, null=True, blank=True)
    team = models.CharField(max_length=120, null=True, blank=True)
    phone = models.CharField(max_length=120, null=True, blank=True)
    date_of_birth = models.DateField(null=True, blank=True)
    duration = models.DurationField(null=True, blank=True)
    starting_number = models.IntegerField(null=True, blank=True)
    alkator_category = models.IntegerField(choices=ALKATOR_CHOICES, default=1)
    alkator_class = models.IntegerField(choices=ALKATOR_CLASSES)
    trans_id = models.CharField(null=True, blank=True, max_length=120)
    price = models.IntegerField(default=690)
    paid = models.BooleanField(default=False)
    invoice_id = models.IntegerField(null=True, blank=True, unique=True)
