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


class User(AbstractUser):
    is_draft = models.BooleanField(default=True)
    # is_draft=True is_active=False => only first page completed
    # is_draft=False is_active=True => all pages has been completed
    # is_draft=False is_active=False => even first page has not been completed
    # is_draft=True is_active=True => impossible variant

    is_active = models.BooleanField(
        'active',
        default=False,
        help_text=(
            'Designates whether this user should be treated as active. '
            'Unselect this instead of deleting accounts.'
        ),
    )
    password = models.CharField(max_length=128, verbose_name='password', null=True)
    
    def is_moderator(self):
        return 'Moderators' in self.groups.values_list('name', flat=True)


# Pillow
# sudo apt-get install libjpeg-dev zlib1g-dev


class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, verbose_name='Пользователь')
    birth_date = models.DateField(null=True, verbose_name='Дата рождения')
    avatar = models.ImageField(null=True, upload_to='avatars', verbose_name='Аватар', default='avatars/no_image.jpeg')
    
    class Meta:
        verbose_name = 'Профиль'
        verbose_name_plural = 'Профили'

    def __str__(self):
        return self.user.get_full_name()
