from rest_framework.generics import ListAPIView
from rest_framework.permissions import AllowAny

from users.models import RoleModel
from users.serializers import RoleListSerializer


class _GetRoles(ListAPIView):
    queryset = RoleModel.objects.all()
    serializer_class = RoleListSerializer

    permission_classes = [AllowAny]


_get_roles = _GetRoles.as_view()


def as_view(request, *args, **kwargs):
    from rest_framework.request import Request
    from users.utils.interfaces import Response

    dj_request = request._request if isinstance(request, Request) else request
    rslt = _get_roles(dj_request, *args, **kwargs)

    ret = Response(
        data=rslt.data, status_code=rslt.status_code)
    return ret
