from django.db import models
from django.core.validators import FileExtensionValidator


class Enquiry(models.Model):
    title = models.CharField(max_length=100, blank=True)
    customer_name = models.CharField(max_length=255)
    business_name = models.CharField(max_length=255, blank=True)
    email = models.EmailField()
    phone_country = models.CharField(max_length=10, default='+971')
    phone_number = models.CharField(max_length=20)
    country = models.CharField(max_length=5, default='AE')
    vin_chasis_number = models.CharField(max_length=50, blank=True, verbose_name='VIN/Chasis Number')
    comments = models.TextField()
    
    is_read = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = 'Enquiry'
        verbose_name_plural = 'Enquiries'
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.customer_name} - {self.email}"
    
    @property
    def full_phone(self):
        return f"{self.phone_country} {self.phone_number}"


class GalleryImage(models.Model):
    image = models.ImageField(
        upload_to='gallery/',
        validators=[FileExtensionValidator(allowed_extensions=['jpg', 'jpeg', 'png'])]
    )
    caption = models.CharField(max_length=255, blank=True)
    
    class Meta:
        ordering = ['-id']
    
    def __str__(self):
        return self.caption or f"Image {self.id}"
    