from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.models import AbstractUser


class UserManager(BaseUserManager):
    def create_or_update_by_email(self, email: str, first_name: str, last_name: str, username: str) -> tuple[
        AbstractUser, bool]:
        # create or sync user with OpenID Data
        user, created = self.model.objects.get_or_create(email=email, defaults={
            "first_name": first_name,
            "last_name": last_name,
            "username": username
        })

        return user, created
