from rest_framework.authentication import (SessionAuthentication,
                                           TokenAuthentication)
from rest_framework.generics import (ListAPIView,
                                     ListCreateAPIView,
                                     RetrieveUpdateDestroyAPIView)

from profiles.models import (Avatar, Favorite, History,
                             ListenerProfile, Rating, SongRequest)
from ..permissions import (IsAdminOrOwner,
                           IsAdminOrReadOnly,
                           IsAdminOwnerOrReadOnly)
from ..serializers.profiles import (AvatarSerializer,
                                    FavoriteSerializer,
                                    HistorySerializer,
                                    ProfileSerializer,
                                    RatingSerializer,
                                    RequestSerializer)


class AvatarListAPI(ListCreateAPIView):
    authentication_classes = (TokenAuthentication, SessionAuthentication)
    permission_classes = (IsAdminOwnerOrReadOnly,)
    queryset = Avatar.objects.all()
    serializer_class = AvatarSerializer


class FavoriteListAPI(ListCreateAPIView):
    authentication_classes = (TokenAuthentication, SessionAuthentication)
    permission_classes = (IsAdminOrReadOnly,)
    queryset = Favorite.objects.all()
    serializer_class = FavoriteSerializer


class HistoryListAPI(ListCreateAPIView):
    authentication_classes = (TokenAuthentication, SessionAuthentication)
    permission_classes = (IsAdminOrReadOnly,)
    queryset = History.objects.all()
    serializer_class = HistorySerializer


class RatingListAPI(ListCreateAPIView):
    authentication_classes = (TokenAuthentication, SessionAuthentication)
    permission_classes = (IsAdminOwnerOrReadOnly,)
    queryset = Rating.objects.all()
    serializer_class = RatingSerializer


class ProfileListAPI(ListAPIView):
    authentication_classes = (TokenAuthentication, SessionAuthentication)
    permission_classes = (IsAdminOrReadOnly,)
    queryset = ListenerProfile.objects.all()
    serializer_class = ProfileSerializer


class ProfileDetailAPI(RetrieveUpdateDestroyAPIView):
    authentication_classes = (TokenAuthentication, SessionAuthentication)
    permission_classes = (IsAdminOwnerOrReadOnly,)
    queryset = ListenerProfile.objects.all()
    serializer_class = ProfileSerializer


class RequestListAPI(ListCreateAPIView):
    authentication_classes = (TokenAuthentication, SessionAuthentication)
    permission_classes = (IsAdminOrReadOnly,)
    queryset = SongRequest.objects.all()
    serializer_class = RequestSerializer
