from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import throttling, status
import pytz
from apps.core.permissions.user_permission import UserPermissionCheck
from apps.core.utils import create_dynamic_pagination

dhaka_tz = pytz.timezone("Asia/Dhaka")




class PermissionsAPIView(APIView):
    """
    API view to retrieve the complete list of available permissions 
    by calling get_master_permissions.
    """
    permission_classes = [UserPermissionCheck]
    http_method_names = ['get']
    throttle_classes = [throttling.ScopedRateThrottle]
    throttle_scope = 'custom_scope_one'
    pagination_class = create_dynamic_pagination(10)

    model_name = "permissions"
    view_permissions = ["list"]

    def get(self, request, *args, **kwargs): # Added *args, **kwargs for consistency
        """
        Calls the function to gather and return all permissions.
        """
        from apps.core.permissions.permissions import get_permissions
        permissions = get_permissions()
        
        # Standardized success response structure
        response_data = {
            "success": True,
            "data": permissions,
            "message": "All permissions list retrieved",
        }
        
        # The status import (status.HTTP_200_OK) is now available from the top-level import
        return Response(response_data, status=status.HTTP_200_OK)
