from django.utils.translation import gettext_lazy as _
from django_filters.rest_framework import DjangoFilterBackend
from drf_spectacular.utils import extend_schema_view
from rest_framework.viewsets import ReadOnlyModelViewSet

from engine.blog.docs.drf.viewsets import POST_SCHEMA
from engine.blog.filters import PostFilter
from engine.blog.models import Post
from engine.blog.serializers import PostSerializer
from engine.core.permissions import EvibesPermission


@extend_schema_view(**POST_SCHEMA)
class PostViewSet(ReadOnlyModelViewSet):
    __doc__ = _(
        "Encapsulates operations for managing and retrieving Post entities in a read-only model view set. "
        "This class is tailored to handle Post objects that are active and allows filtration based on defined "
        "filters. It integrates with Django's backend filtering system and ensures operations align with the "
        "defined permissions. The view set also includes an additional 'retrieve' permission configuration."
    )

    serializer_class = PostSerializer
    permission_classes = (EvibesPermission,)
    queryset = Post.objects.filter(is_active=True)
    filter_backends = [DjangoFilterBackend]
    filterset_class = PostFilter
    additional = {"retrieve": "ALLOW"}
