from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.viewsets import ReadOnlyModelViewSet

from blog.filters import PostFilter
from blog.models import Post
from blog.serializers import PostSerializer
from core.permissions import EvibesPermission


class PostViewSet(ReadOnlyModelViewSet):  # type: ignore [type-arg]
    """
    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.

    Attributes:
        serializer_class: Specifies the serializer to be used for Post objects.
        permission_classes: Defines the permissions required to interact with this view set.
        queryset: Determines the initial queryset, filtered to include only active Post objects.
        filter_backends: Lists the backends to be used for filtering querysets.
        filterset_class: Defines the set of filters used for filtering Post objects.
        additional: Contains additional configuration, such as specific action permissions.
    """

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