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


class CustomUser(AbstractUser):
    """
    Custom User Model with role-based authentication.
    Extends Django's AbstractUser to add role functionality.
    """
    
    class Role(models.TextChoices):
        INFLUENCER = 'INFLUENCER', 'Influencer'
        BUSINESS = 'BUSINESS', 'Business'
    
    role = models.CharField(
        max_length=20,
        choices=Role.choices,
        default=Role.INFLUENCER,
        help_text="User role: Influencer or Business"
    )
    
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    
    class Meta:
        verbose_name = 'User'
        verbose_name_plural = 'Users'
    
    def __str__(self):
        return f"{self.username} ({self.get_role_display()})"
    
    @property
    def is_influencer(self):
        return self.role == self.Role.INFLUENCER
    
    @property
    def is_business(self):
        return self.role == self.Role.BUSINESS
