from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from .models import UserRole


@api_view(["GET"])
@permission_classes([IsAuthenticated])
def current_user_api(request):
    return Response(
        {
            "id": request.user.id,
            "username": request.user.username,
            "email": request.user.email,
            "first_name": request.user.first_name,
            "last_name": request.user.last_name,
            "role": UserRole.resolve_for(request.user),
            "role_label": UserRole.label_for(request.user),
            "is_superuser": request.user.is_superuser,
        }
    )
