"""User Model."""

# Django
from django.db import models 
from django.contrib.auth.models import AbstractUser

# Utilities
from .utils import ApiModel


class User(ApiModel, AbstractUser):

    email = models.EmailField(
        'email',
        unique = True,
    )

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username', 'first_name', 'last_name']
    
    is_student = models.BooleanField(default=False)
    
    class Meta:
        verbose_name='Usuario'
        verbose_name_plural='Usuarios'

    def __str__(self):
        return self.username
    
    def get_short_name(self):
        return self.username


class ProfileUser(ApiModel):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    approved_courses = models.ManyToManyField('api.ResultContest',
            related_name='user_aproved_courses', blank=True, null=True)
    tests_performed = models.ManyToManyField('api.ResultTest',
            related_name='user_result_test', blank=True)
    
    class Meta:
        verbose_name = 'Usuario - Perfil'
        verbose_name_plural = 'Usuarios - Perfiles'
    
    def __str__(self):
        return str(self.user)


[((202, 241), 'django.db.models.EmailField', 'models.EmailField', (['"""email"""'], {'unique': '(True)'}), "('email', unique=True)\n", (219, 241), False, 'from django.db import models\n'), ((381, 415), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(False)'}), '(default=False)\n', (400, 415), False, 'from django.db import models\n'), ((666, 718), 'django.db.models.OneToOneField', 'models.OneToOneField', (['User'], {'on_delete': 'models.CASCADE'}), '(User, on_delete=models.CASCADE)\n', (686, 718), False, 'from django.db import models\n'), ((742, 850), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['"""api.ResultContest"""'], {'related_name': '"""user_aproved_courses"""', 'blank': '(True)', 'null': '(True)'}), "('api.ResultContest', related_name=\n    'user_aproved_courses', blank=True, null=True)\n", (764, 850), False, 'from django.db import models\n'), ((880, 969), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['"""api.ResultTest"""'], {'related_name': '"""user_result_test"""', 'blank': '(True)'}), "('api.ResultTest', related_name='user_result_test',\n    blank=True)\n", (902, 969), False, 'from django.db import models\n')]