"""This module contains the v2 api related-views for the accounts app"""

from rest_framework import viewsets
from rest_framework.decorators import list_route
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from mtp.apps.accounts.models import MTPUser
from mtp.apps.api.mixins import SoftDestroyModelMixin

from .serializers import MTPUserSerializer


class UserViewSet(SoftDestroyModelMixin, viewsets.ModelViewSet):
    """Viewset for the ``MTPUser`` model"""

    queryset = MTPUser.objects.non_deleted()
    permission_classes = [IsAuthenticated]
    serializer_class = MTPUserSerializer

    @list_route()
    def me(self, request):
        """Retrieve and serialize the authenticated user

        Returns
        -------
        ``rest_framework.response.Response`` instance
            A response containing the serialized user

        """

        serializer = self.get_serializer(request.user)

        return Response(serializer.data)

