
from django.db import models
from django.utils import timezone


class LoanLead(models.Model):

    LOAN_TYPE_CHOICES = [
        ('personal', 'Personal Loan'),
        ('business', 'Business Loan'),
        ('mortgage', 'Mortgage Loan'),
        ('vehicle', 'Vehicle Loan'),
    ]

    SOURCE_CHOICES = [
        ('reference', 'Reference'),
        ('social_media', 'Social Media'),
        ('direct', 'Direct Walk-in'),
        ('advertisement', 'Advertisement'),
    ]

    STATUS_CHOICES = [
        ('active', 'Active'),
        ('confirmed', 'Confirmed'),
    ]

    PAYMENT_TYPE_CHOICES = [
        ('daily', 'Daily'),
        ('weekly', 'Weekly'),
        ('monthly', 'Monthly'),
    ]

    lead_date = models.DateField(default=timezone.localdate)
    followup_date = models.DateField()

    name = models.CharField(max_length=150)
    place = models.CharField(max_length=150, blank=True, null=True)
    phone = models.CharField(max_length=10)

    loan_type = models.CharField(
        max_length=20, choices=LOAN_TYPE_CHOICES
    )
    loan_amount = models.DecimalField(
        max_digits=12, decimal_places=2, blank=True, null=True
    )
    payment_type = models.CharField(
        max_length=20,
        choices=PAYMENT_TYPE_CHOICES,
        blank=True, null=True
    )

    source = models.CharField(max_length=20, choices=SOURCE_CHOICES)
    source_details = models.CharField(
        max_length=200, blank=True, null=True
    )

    status = models.CharField(
        max_length=20, choices=STATUS_CHOICES, default='active'
    )

    staff_name = models.CharField(
        max_length=150, blank=True, null=True
    )
    staff_id = models.CharField(
        max_length=50, blank=True, null=True
    )

    agent_name = models.CharField(
        max_length=150, blank=True, null=True
    )
    agent_mobile = models.CharField(
        max_length=10, blank=True, null=True
    )

    purpose = models.TextField(blank=True, null=True)
    remarks = models.TextField(blank=True, null=True)

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'loan_leads'
        ordering = ['-id']

    def __str__(self):
        return self.name
