from django.contrib.auth.models import AbstractUser
from django.contrib.auth.validators import UnicodeUsernameValidator
from django.db import models
from django.utils import timezone


class CustomUser(AbstractUser):
    """
    Modèle de l'utilisateur de l'application
    """

    class Cols():
        """ Constantes pour les noms de colonnes """

        # relations one-to-many
        O2M_GROUPE_FE_PCP = 'pcpfegroupe_set'
        O2M_SOUS_VIVIER   = 'sousvivier_set'
        M2M_SOUS_VIVIERS  = 'sous_vivier'
        # relations many-to-many
        M2M_FORMATION_EMPLOIS = 'formation_emploi'

    # id = models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')
    id = models.IntegerField(auto_created=True, primary_key=True, verbose_name='Id SAP')
    password = models.CharField(max_length=128, verbose_name='password')
    last_login = models.DateTimeField(blank=True, null=True, verbose_name='last login')
    is_superuser = models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')
    username = models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[UnicodeUsernameValidator()], verbose_name='username')
    first_name = models.CharField(null=True, blank=True, max_length=150, verbose_name='first name')
    last_name = models.CharField(null=True, blank=True, max_length=150, verbose_name='last name')
    email = models.EmailField(null=True, blank=True, max_length=254, verbose_name='email address')
    is_staff = models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')
    is_active = models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')
    date_joined = models.DateTimeField(default=timezone.now, verbose_name='date joined')
    grade = models.CharField(blank=True, max_length=100, null=True)

    REQUIRED_FIELDS = ['id']
