from django.db import models
from customer_api.models import *
from subscription_api.models import *
from django.db.models.deletion import CASCADE, SET_NULL, DO_NOTHING


# Create your models here.

class LawyerSubscriptions(models.Model):
    customer = models.ForeignKey(Customer,on_delete=DO_NOTHING,null=True)
    plan = models.ForeignKey(LawyerSubscriptionPlan,on_delete=DO_NOTHING,null=True)
    sub_start_date = models.DateField(auto_now_add=True,null=False)
    sub_expiry_date = models.DateField(null=True)
    is_active = models.BooleanField(default=False)
    start_date = models.DateTimeField(auto_now_add=True,null=False)
    total_hiring_requests=models.IntegerField(default=0,null= True)

    end_date = models.DateTimeField(null=True)

    class Meta:
        db_table = "lawyer_subscriptions"



class LawyerContractDeals(models.Model):
    inquiry = models.ForeignKey(inquirePropertyProject,on_delete=DO_NOTHING,null=True) 
    customer = models.ForeignKey(Customer,on_delete=DO_NOTHING,null=True,related_name="customer_loc")
    lawyer = models.ForeignKey(Customer,on_delete=DO_NOTHING,null=True,related_name="lawyer_loc")
    req_status=models.CharField(max_length=150,null=True,default='pending')
    start_date = models.DateTimeField(auto_now_add=True)
    end_date = models.DateTimeField(null=True)

    class Meta:
        db_table = "lawyer_contract_deals"




class lawyerRatingAndReview(models.Model):
    send_user_customer = models.ForeignKey(Customer, on_delete=models.CASCADE, related_name='send_user_customer')
    lawyer_receive_customer = models.ForeignKey(Customer, on_delete=models.CASCADE, related_name='lawyer_receive_customer')
    rating = models.IntegerField(default=0)
    review = models.TextField(null=True)
    start_date = models.DateTimeField(auto_now_add=True,null=False)
    end_date = models.DateTimeField(null=True)

    class Meta:
	    db_table = "lawyer_rating_and_review" 
         



     
class ConversationLawyer(models.Model):
    customer = models.ForeignKey(
        Customer,
        on_delete=models.CASCADE,
        related_name='conversation_lawyer_customer'  # Unique related_name
    )
    lawyer = models.ForeignKey(
        Customer,
        on_delete=models.CASCADE,
        related_name='conversation_lawyer_lawyer'  # Unique related_name
    )
    twilio_channel_sid = models.CharField(max_length=255, blank=True, null=True)
    customer_twilio_id = models.CharField(max_length=200, null=True)
    lawyer_twilio_id = models.CharField(max_length=200, null=True)
    last_message = models.DateTimeField(null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    end_date = models.DateTimeField(null=True)

    class Meta:
        db_table = 'conversation_lawyer'


class LawyerPropertyRequests(models.Model):
    customer = models.ForeignKey(Customer,on_delete=DO_NOTHING,null=True,related_name='customer_requests_lawyer')
    lawyer = models.ForeignKey("customer_api.customer",on_delete=DO_NOTHING,null=True,related_name='lawyer_request_lawyer')
    location_agency = models.ForeignKey("customer_api.customer",on_delete=DO_NOTHING,null=True,related_name='location_agency_lawyer')
    mobile_number =  models.CharField(max_length=30,default='')
    name =  models.CharField(max_length=50,default='')
    email =  models.CharField(max_length=50,default='')
    property_type = models.CharField(max_length=250,default='')
    price = models.CharField(max_length=25000,default='')
    is_viewed = models.BooleanField(default=False)
    is_published = models.BooleanField(default=False)
    is_contacted = models.BooleanField(default=False)
    property_status = models.CharField(max_length=244,null=True,default="pending")
    start_date = models.DateTimeField(auto_now_add=True)
    end_date = models.DateTimeField(null=True)
    property_name = models.CharField(max_length=250,default='')
    property_id=models.CharField(max_length=250,default='')
    property_image = models.TextField( null=True, blank=True)
    property_video = models.TextField(null=True, blank=True)
    property_doc = models.TextField(null=True, blank=True)
    do_it_by_type=models.CharField(max_length=250,default='')
    finalized_status=models.CharField(max_length=200,null=True)
    buyer_signature = models.TextField(default='')
    buyer_status = models.CharField(max_length=150,default='')
    is_contract_created = models.BooleanField(default=False)
    status = models.CharField(max_length=50,default='')
    rejection_reason=models.CharField(max_length=1000,null=True)

    class Meta:
        db_table = 'lawyer_property_request'
            


class LawyerApprovedProperty(models.Model):
	lawyer = models.ForeignKey(Customer,on_delete=DO_NOTHING,null=True,related_name='lawyer_request')
	customer = models.ForeignKey(Customer,on_delete=DO_NOTHING,null=True,related_name='customer_request')
	property_request = models.ForeignKey(LawyerPropertyRequests,on_delete=DO_NOTHING,null=True)
	is_requested = models.BooleanField(default=True)
	start_date = models.DateTimeField(auto_now_add=True)
	end_date = models.DateTimeField(null=True)

	class Meta:
		db_table = 'lawyer_approved_request'
            


class LawyerDoItPropertyContract(models.Model):
    lawyer_doit = models.ForeignKey(Customer,on_delete=DO_NOTHING,null=True,related_name='lawyer_doit')
    customer_doit = models.ForeignKey(Customer,on_delete=DO_NOTHING,null=True,related_name='customer_doit')
    property_request = models.ForeignKey(LawyerPropertyRequests,on_delete=DO_NOTHING,null=True)
    contract_file = models.CharField(max_length=250,default='')
    company_name = models.CharField(max_length=150,default='')
    full_name = models.CharField(max_length=100,default='')
    tasks = models.TextField(default='')
    owner_full_name = models.CharField(max_length=100,default='')
    owner_email = models.CharField(max_length=150,default='')
    owner_signature = models.TextField(default='')
    buyer_full_name = models.CharField(max_length=100,default='')
    buyer_email = models.CharField(max_length=150,default='')
    buyer_signature = models.TextField(default='')
    status =  models.CharField(max_length=150,default='')
    start_date = models.DateTimeField(auto_now_add=True,null=False)
    end_date = models.DateTimeField(null=True)

    class Meta:
        db_table = "lawyer_doit_property_contracts"