from rest_framework.generics import RetrieveAPIView
from rest_framework.permissions import IsAuthenticated

from users.models import UserModel
from users.serializers import UserRetrieveSerializer


class _GetUserBaseInfo(RetrieveAPIView):
    queryset = UserModel.objects.all()
    serializer_class = UserRetrieveSerializer

    permission_classes = [IsAuthenticated]


_get_user_base_info = _GetUserBaseInfo.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_user_base_info(dj_request, pk=request.user.id, *args, **kwargs)

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