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


class User(AbstractUser):

    class ROLE_CHOICES(models.TextChoices):
        admin = 'admin', 'Administrateur',
        supervisor = 'supervisor', 'Superviseur',

    role = models.CharField(max_length=20, choices=ROLE_CHOICES)
    profile_pic = models.ImageField(upload_to='profiles', blank=True)
    telephone = models.CharField(max_length=20, unique=True, null=True, blank=True)

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)

    def __str__(self):
        return f'{self.first_name} {self.last_name}'

    def get_absolute_url(self):
        return reverse('utilisateur:user_detail', args=[self.id])
