from django.db import models

class Trip(models.Model):
    SECTION_CHOICES = [
        ("featured", "Viajes destacados"),
        ("daytrip", "Sin pernocta: ida y vuelta en el día"),
        ("hotel", "Circuitos con hotel"),
    ]
    title = models.CharField("Título", max_length=160)
    destination = models.CharField("Destino", max_length=120)
    subtitle = models.CharField("Subtítulo", max_length=180, blank=True)
    description = models.TextField("Descripción", blank=True)
    image = models.ImageField("Imagen principal", upload_to="trips/")
    price = models.DecimalField("Precio desde (€)", max_digits=8, decimal_places=2)
    duration = models.CharField("Duración", max_length=80, help_text="Ej.: 1 día · ida y vuelta")
    departure = models.CharField("Salida", max_length=120, blank=True)
    badge = models.CharField("Etiqueta", max_length=60, blank=True, help_text="Ej.: Últimas plazas")
    section = models.CharField("Sección", max_length=20, choices=SECTION_CHOICES, default="featured")
    order = models.PositiveIntegerField("Orden", default=0)
    published = models.BooleanField("Publicado", default=True)
    created_at = models.DateTimeField("Creado", auto_now_add=True)

    class Meta:
        ordering = ["order", "-created_at"]
        verbose_name = "Viaje"
        verbose_name_plural = "Viajes"

    def __str__(self):
        return f"{self.title} — {self.destination}"


class TripPhoto(models.Model):
    trip = models.ForeignKey(Trip, on_delete=models.CASCADE, related_name="photos", verbose_name="Viaje")
    image = models.ImageField("Fotografía", upload_to="trip_gallery/")
    caption = models.CharField("Pie de foto", max_length=180, blank=True)
    order = models.PositiveIntegerField("Orden", default=0)
    uploaded_at = models.DateTimeField("Fecha de subida", auto_now_add=True)

    class Meta:
        ordering = ["order", "-uploaded_at"]
        verbose_name = "Fotografía de viaje"
        verbose_name_plural = "Fotografías de viajes"

    def __str__(self):
        return f"Foto de {self.trip.title}"
