from django.db import models
from common.models.base import TimeStampedModel
from specialty_and_services.models import SpecialtyAndServices
from area_of_operation.models import AreaOfOperation
from users.models import User
from api.property_api.country.models.country import Country

class Agent(TimeStampedModel):
    name = models.CharField(max_length=50)
    email = models.EmailField(blank=False)
    contact_no = models.CharField(max_length=15)
    profile_picture = models.ImageField(upload_to="agent_profile_picture",blank=True,null=True)
    cover_picture = models.ImageField(upload_to="agent_cover_picture",blank=True,null=True)
    designation = models.CharField(max_length=255, blank=True,null=True)
    company_name = models.CharField(max_length=255,blank=True,null=True)
    bio = models.TextField(blank=True,null=True)
    specialty_and_services = models.ManyToManyField(SpecialtyAndServices,related_name="agent",blank=True)
    area_of_operation = models.ManyToManyField(AreaOfOperation,related_name="agent",blank=True)
    agent_user = models.OneToOneField(User,on_delete=models.CASCADE,blank=True,related_name='agent')
    verified = models.BooleanField(default=False)
    country = models.ForeignKey(Country,blank=True,null=True,on_delete=models.SET_NULL)
    linkedin = models.CharField(max_length=255, blank=True,null=True)
    facebook = models.CharField(max_length=255, blank=True,null=True)
    youtube = models.CharField(max_length=255, blank=True,null=True)
    whatsapp = models.CharField(max_length=15, blank=True, null=True)
    username = models.CharField(max_length=255,blank=True,null=True)
    has_username = models.BooleanField(default=False)

    def __str__(self):
        return f"{self.name}: {self.contact_no}"
    
    def soft_delete(self):
        if self.is_active:
            self.is_active = False
            self.save(update_fields=['is_active'])
