from django.conf import settings
from django.db import models


class StaffProfile(models.Model):
    STAFF_ROLE_CHOICES = [
        ('operations_admin', 'Operations Admin'),
        ('property_care_reviewer', 'Property Care Reviewer'),
        ('rental_reviewer', 'Rental Reviewer'),
        ('dating_reviewer', 'Dating Profile Reviewer'),
        ('service_partner_reviewer', 'Service Partner Reviewer'),
        ('affiliate_manager', 'Affiliate Manager'),
        ('finance_staff', 'Finance Staff'),
        ('general_staff', 'General Staff'),
    ]

    user = models.OneToOneField(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        related_name='staff_profile'
    )

    designation = models.CharField(
        max_length=120,
        blank=True,
        help_text="Internal staff designation or working title."
    )

    staff_role = models.CharField(
        max_length=50,
        choices=STAFF_ROLE_CHOICES,
        default='general_staff'
    )

    whatsapp_number = models.CharField(
        max_length=30,
        blank=True
    )

    phone_number = models.CharField(
        max_length=30,
        blank=True
    )

    nid_number = models.CharField(
        max_length=50,
        blank=True,
        help_text="National Identity Card number or other internal identity reference."
    )

    address = models.TextField(
        blank=True
    )

    profile_image = models.ImageField(
        upload_to='myadmin/staff_profiles/',
        blank=True,
        null=True
    )

    is_operations_active = models.BooleanField(
        default=True,
        help_text="Indicates whether this staff member is currently active in internal operational workflows."
    )

    internal_notes = models.TextField(
        blank=True
    )

    created_at = models.DateTimeField(
        auto_now_add=True
    )

    updated_at = models.DateTimeField(
        auto_now=True
    )

    class Meta:
        verbose_name = "Staff Profile"
        verbose_name_plural = "Staff Profiles"
        ordering = ['user__first_name', 'user__last_name', 'user__username']

    def __str__(self):
        full_name = self.user.get_full_name().strip()
        return full_name or self.user.username

    @property
    def full_name(self):
        return self.user.get_full_name().strip() or self.user.username

    @property
    def email(self):
        return self.user.email