from django.db import models
from django.utils.text import slugify

class ServiceCategory(models.Model):
    name = models.CharField(max_length=100)
    slug = models.SlugField(unique=True, blank=True)
    description = models.TextField(blank=True)

    class Meta:
        verbose_name = "Service Category"
        verbose_name_plural = "Service Categories"

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.name)
        super().save(*args, **kwargs)

    def __str__(self):
        return self.name


class Service(models.Model):
    category = models.ForeignKey(ServiceCategory, on_delete=models.SET_NULL, null=True, blank=True, related_name='services')
    title = models.CharField(max_length=150)
    slug = models.SlugField(unique=True, blank=True)
    short_description = models.TextField(help_text="Brief summary for cards")
    full_description = models.TextField(help_text="Full in-depth service overview")
    icon = models.CharField(max_length=50, default="Code", help_text="Lucide icon name: Code, Globe, Smartphone, Palette, Cpu, Shield, Database, Wrench")
    key_features = models.JSONField(default=list, help_text="List of feature bullet points e.g. ['Custom Architecture', 'High Scalability']")
    benefits = models.JSONField(default=list, help_text="List of client benefits")
    technologies = models.CharField(max_length=255, default="React, Django, Python, PostgreSQL, Flutter, Docker", help_text="Key tech stack used")
    image_url = models.URLField(blank=True, default="https://images.unsplash.com/photo-1498050108023-c5249f4df085?auto=format&fit=crop&w=800&q=80")
    order = models.PositiveIntegerField(default=0)
    is_featured = models.BooleanField(default=True)
    is_active = models.BooleanField(default=True)

    class Meta:
        ordering = ['order', 'title']
        verbose_name = "Service"
        verbose_name_plural = "Services"

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.title)
        super().save(*args, **kwargs)

    def __str__(self):
        return self.title
