from rest_framework import generics

from common.views import (
    APIKeyAuthentication,
    DashboardTokenAuthentication,
    ListAPIViewOnlyMixin,
    MobileTokenAuthentication,
    StandardSetPagination,
    SubscriptionPlanMixin,
)
from .content_information_models import (
    ContentInformation,
    ContentInformationLanguage,
    TargetAudience,
    ContentObjective,
)
from .content_information_serializers import (
    ContentInformationSerializerBasic,
    ContentInformationLanguageSerializer,
    TargetAudienceSerializer,
    ContentObjectiveSerializer,
    ContentInformationSerializerDetail,
)


class ContentInformationListMobileView(SubscriptionPlanMixin, generics.ListAPIView,ListAPIViewOnlyMixin):
    pagination_class = StandardSetPagination
    authentication_classes = [APIKeyAuthentication,MobileTokenAuthentication]
    queryset = ContentInformation.objects.all().order_by("id")
    serializer_class = ContentInformationSerializerBasic


class ContentInformationDetailMobileView(SubscriptionPlanMixin,generics.RetrieveAPIView):
    authentication_classes = [APIKeyAuthentication,MobileTokenAuthentication]
    queryset = ContentInformation.objects.all()
    lookup_field = "id"
    serializer_class = ContentInformationSerializerDetail


class ContentInformationListDashboardView(generics.ListCreateAPIView):
    pagination_class = StandardSetPagination
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = ContentInformation.objects.all().order_by("id")
    serializer_class = ContentInformationSerializerBasic


class ContentInformationDetailDashboardView(generics.RetrieveUpdateDestroyAPIView):
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = ContentInformation.objects.all()
    lookup_field = "id"
    serializer_class = ContentInformationSerializerBasic

    def get_serializer_class(self):
        if self.request.method == "GET":
            return ContentInformationSerializerDetail
        return self.serializer_class


class ContentInformationLanguageListDashboardView(generics.ListCreateAPIView):
    pagination_class = StandardSetPagination
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = ContentInformationLanguage.objects.all().order_by("id")
    serializer_class = ContentInformationLanguageSerializer


class ContentInformationLanguageDetailDashboardView(generics.RetrieveUpdateDestroyAPIView):
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = ContentInformationLanguage.objects.all()
    lookup_field = "id"
    serializer_class = ContentInformationLanguageSerializer


class TargetAudienceListDashboardView(generics.ListCreateAPIView):
    pagination_class = StandardSetPagination
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = TargetAudience.objects.all().order_by("id")
    serializer_class = TargetAudienceSerializer


class TargetAudienceDetailDashboardView(generics.RetrieveUpdateDestroyAPIView):
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = TargetAudience.objects.all()
    lookup_field = "id"
    serializer_class = TargetAudienceSerializer


class ContentObjectiveListDashboardView(generics.ListCreateAPIView):
    pagination_class = StandardSetPagination
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = ContentObjective.objects.all().order_by("id")
    serializer_class = ContentObjectiveSerializer


class ContentObjectiveDetailDashboardView(generics.RetrieveUpdateDestroyAPIView):
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = ContentObjective.objects.all()
    lookup_field = "id"
    serializer_class = ContentObjectiveSerializer
