from django.contrib.auth.models import BaseUserManager


class UserManger(BaseUserManager):

    def create_user(self, nom, prenoms, email, password, **other_fields):
        email = self.normalize_email(email=email)
        user = self.model(email=email, nom=nom, prenoms=prenoms, **other_fields)

        if not email:
            raise ValueError("Vous devez entrer une adresse email")
            
        user.set_password(password)
        user.save()
        return user

    def create_superuser(self, nom, prenoms, email, password, **other_fields):
        other_fields.setdefault('is_staff', True)
        other_fields.setdefault('is_superuser', True)
        other_fields.setdefault('is_active', True)


        if other_fields.get('is_staff') is not True:
            raise ValueError("Veillez mettre is_staff = True")

        if other_fields.get('is_superuser') is not True:
            raise ValueError("Veillez mettre is_superuser = True")

        return self.create_user(nom, prenoms, email, password, **other_fields)
