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

# Create your models here.

class HeroSlide(models.Model):
    title = models.CharField(max_length=200, help_text="Title to display on the slide")
    subtitle = models.TextField(blank=True, help_text="Optional subtitle or description")
    image = models.ImageField(upload_to='hero_slides/', help_text="Image for the slide (recommended size: 1920x1080)")
    button_text = models.CharField(max_length=50, blank=True, help_text="Optional call-to-action button text")
    button_url = models.CharField(max_length=200, blank=True, help_text="URL for the call-to-action button")
    order = models.PositiveIntegerField(default=0, help_text="Order in which the slide appears (lower numbers appear first)")
    is_active = models.BooleanField(default=True, help_text="Whether this slide is currently displayed")
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ['order', '-created_at']
        verbose_name = 'Hero Slide'
        verbose_name_plural = 'Hero Slides'

    def __str__(self):
        return self.title

    def save(self, *args, **kwargs):
        # Ensure there's always a button URL if there's button text
        if self.button_text and not self.button_url:
            self.button_url = '#'
        super().save(*args, **kwargs)
