from django.db import models


class HtmlBundle(models.Model):
    title = models.CharField(max_length=200, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self) -> str:
        return self.title or f"Bundle {self.pk}"


class HtmlDocument(models.Model):
    bundle = models.ForeignKey(HtmlBundle, related_name="documents", on_delete=models.CASCADE)
    original_name = models.CharField(max_length=255)
    order = models.PositiveIntegerField(default=1)
    content_text = models.TextField()

    class Meta:
        ordering = ["order", "id"]

    def __str__(self) -> str:
        return f"{self.original_name} ({self.bundle_id})"


class HtmlExport(models.Model):
    bundle = models.ForeignKey(HtmlBundle, related_name="exports", on_delete=models.CASCADE)
    created_at = models.DateTimeField(auto_now_add=True)
    file_name = models.CharField(max_length=255)

    def __str__(self) -> str:
        return self.file_name
