"""Main app views."""
from django.http import Http404
from django.conf import settings
from rest_framework import generics, permissions
from rest_framework.response import Response

from main import methods, models, serializers

#
# class FeatureViewMixin:
#     """Feature view mixin."""
#
#     queryset = models.Feature.objects.all()
#     serializer_class = serializers.FeatureSerializer
#     permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
#
#
# class FeaturesLCView(FeatureViewMixin, generics.ListCreateAPIView):
#     """Site features LC View."""
#
#     pagination_class = None
#
#
# class FeaturesRUDView(FeatureViewMixin, generics.RetrieveUpdateDestroyAPIView):
#     """Site features RUD View."""
#
#
# class SiteFeaturesViewMixin:
#     """Site feature view mixin."""
#
#     queryset = models.SiteFeature.objects.all()
#     serializer_class = serializers.SiteFeatureSerializer
#     permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
#
#
# class SiteFeaturesLCView(SiteFeaturesViewMixin, generics.ListCreateAPIView):
#     """Site features LC."""
#
#     pagination_class = None
#
#
# class SiteFeaturesRUDView(SiteFeaturesViewMixin,
#                           generics.RetrieveUpdateDestroyAPIView):
#     """Site features RUD."""
from utils.serializers import EmptySerializer


class AwardView(generics.ListAPIView):
    """Awards list view."""
    serializer_class = serializers.AwardSerializer
    queryset = models.Award.objects.all()
    permission_classes = (permissions.AllowAny,)


class AwardRetrieveView(generics.RetrieveAPIView):
    """Award retrieve view."""
    serializer_class = serializers.AwardSerializer
    queryset = models.Award.objects.all()
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)


class CarouselListView(generics.ListAPIView):
    """Return list of carousel items."""

    queryset = models.Carousel.objects.is_parsed().active()
    serializer_class = serializers.CarouselListSerializer
    permission_classes = (permissions.AllowAny,)
    pagination_class = None

    def get_queryset(self):
        country_code = self.request.country_code
        qs = models.Carousel.objects.is_parsed().active()
        if country_code:
            qs = qs.by_country_code(country_code)
        return qs


class DetermineLocation(generics.GenericAPIView):
    """Determine user's location."""

    permission_classes = (permissions.AllowAny,)
    serializer_class = EmptySerializer

    def get(self, request, *args, **kwargs):
        longitude, latitude = methods.determine_coordinates(request)
        city = methods.determine_user_city(request)
        country_name = methods.determine_country_name(request)
        country_code = methods.determine_country_code(request)
        if longitude and latitude and city and country_name:
            return Response(data={
                'latitude': latitude,
                'longitude': longitude,
                'city': city,
                'country_name': country_name,
                'country_code': country_code,
            })
        raise Http404
