from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiResponse

from api.viewsets.common.authenticated import AuthUserReadOnlyModelViewSet

from centurion.serializers.permission import (
    Permission,
    PermissionViewSerializer
)



@extend_schema_view(
    list = extend_schema(
        summary = 'Fetch all permissions',
        description='',
        responses = {
            200: OpenApiResponse(description='', response=PermissionViewSerializer),
        }
    ),
    retrieve = extend_schema(
        summary = 'Fetch a permission',
        description='',
        responses = {
            200: OpenApiResponse(description='', response=PermissionViewSerializer),
        }
    ),
)
class ViewSet(
    AuthUserReadOnlyModelViewSet
):


    model = Permission

    view_description = 'Centurion Permissions'


    def get_queryset(self):

        if self.queryset is None:

            self.queryset = self.model.objects.select_related('content_type')

        return self.queryset


    def get_serializer_class(self):

        return PermissionViewSerializer

    def get_view_name(self):

        if self.detail:

            return 'Permission'
        
        return 'Permissions'
