from django.db import models

class ContactMessage(models.Model):
    STATUS_CHOICES = [
        ('new', 'New Lead'),
        ('contacted', 'Contacted Client'),
        ('in_discussion', 'In Discussion'),
        ('resolved', 'Resolved / Closed'),
    ]
    name = models.CharField(max_length=150)
    email = models.EmailField()
    phone = models.CharField(max_length=50)
    company = models.CharField(max_length=150, blank=True)
    subject = models.CharField(max_length=200)
    service_interested = models.CharField(max_length=100, blank=True, default="General Inquiry")
    message = models.TextField()
    status = models.CharField(max_length=30, choices=STATUS_CHOICES, default='new')
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['-created_at']
        verbose_name = "Contact Message"
        verbose_name_plural = "Contact Messages"

    def __str__(self):
        return f"{self.name} - {self.subject} ({self.get_status_display()})"


class ProjectInquiry(models.Model):
    STATUS_PIPELINE = [
        ('new', 'NEW LEAD'),
        ('contacted', 'CONTACTED'),
        ('in_discussion', 'IN DISCUSSION'),
        ('quoted', 'QUOTED'),
        ('won', 'WON (PROJECT STARTED)'),
        ('lost', 'LOST'),
    ]
    name = models.CharField(max_length=150)
    company = models.CharField(max_length=150)
    email = models.EmailField()
    phone = models.CharField(max_length=50)
    service = models.CharField(max_length=100)
    estimated_budget = models.CharField(max_length=100, default="$1,000 - $5,000")
    timeline = models.CharField(max_length=100, default="1 - 3 Months")
    project_description = models.TextField()
    attachment = models.FileField(upload_to='inquiry_attachments/', blank=True, null=True)
    status = models.CharField(max_length=30, choices=STATUS_PIPELINE, default='new')
    admin_notes = models.TextField(blank=True, help_text="Internal sales and negotiation notes")
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['-created_at']
        verbose_name = "Project Inquiry / Quote"
        verbose_name_plural = "Project Inquiries & Quotes"

    def __str__(self):
        return f"{self.company} ({self.name}) - {self.service} [{self.get_status_display()}]"
