from django.db import models
from . import UnregisteredTeam
import uuid

class UnregisteredPlayer(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
    unregistered_team = models.ForeignKey(UnregisteredTeam, on_delete=models.SET_NULL, related_name='unregistered_players', null=True, blank=True)
    first_name = models.CharField(max_length=50, blank=True)
    last_name = models.CharField(max_length=50, blank=True)
    licence_id = models.CharField(max_length=50, null=True, blank=True)

    def __str__(self):
        return self.name()

    def name(self):
        return f"{self.first_name} {self.last_name}"

    def shortened_name(self):
        name = self.name()
        if len(name) > 20 and self.first_name:
            name = f"{self.first_name[0]}. {self.last_name}"
        if len(name) > 20:
            name_parts = self.last_name.split(" ")
            name = f"{self.first_name[0]}. {name_parts[0]}"
        return name
