from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User

from .models import UserProfile


@receiver(post_save, sender=User)
def create_profile_for_user(sender, instance, created, **kwargs):
    """Auto-create a UserProfile (default Client) whenever a User is created."""
    if created:
        UserProfile.objects.get_or_create(
            user=instance,
            defaults={"user_type": UserProfile.UserType.CLIENT},
        )
