from django.db import models
from django.utils.translation import gettext_lazy as _
from django_ckeditor_5.fields import CKEditor5Field


class StaticContent(models.Model):
    name = models.CharField(
        verbose_name=_("Name"),
        help_text=_("Category name"),
        max_length=512,
        unique=True,
    )
    text = CKEditor5Field(
        verbose_name=_("Content"),
        help_text=_("Text as shown to the visitors"),
        blank=True,
    )
    url_path = models.CharField(
        verbose_name=_("URL path"),
        help_text=_("URL path where the content is included."),
    )

    class Meta:
        verbose_name = _("Static content")
        verbose_name_plural = _("Static contents")
        indexes = [
            models.Index(fields=["name"]),
        ]

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return self.url_path
