from rest_framework import generics
from django_filters.rest_framework import DjangoFilterBackend

from common.views import (
    APIKeyAuthentication,
    DashboardTokenAuthentication,
    MobileTokenAuthentication,
    StandardSetPagination,
    SubscriptionPlanMixin,
)

from .models import (
    DiaperTrackerGroup,
    DiaperTrackerRow,
    DiaperTrackerType,
    DiaperTrackerTypeLanguage,
    GrowthTracker,
)
from .serializers import (
    DiaperTrackerGroupSerializer,
    DiaperTrackerRowSerializer,
    DiaperTrackerTypeLanguageSerializer,
    DiaperTrackerTypeSerializer,
    GrowthTrackerSerializer,
)


class GrowthTrackerListMobileView(
    SubscriptionPlanMixin, generics.ListCreateAPIView
):
    authentication_classes = [APIKeyAuthentication, MobileTokenAuthentication]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ["medicalProfileId"]
    pagination_class = StandardSetPagination
    queryset = GrowthTracker.objects.order_by("-date")
    serializer_class = GrowthTrackerSerializer


class GrowthTrackerDetailMobileView(
    SubscriptionPlanMixin, generics.RetrieveUpdateDestroyAPIView
):
    authentication_classes = [APIKeyAuthentication, MobileTokenAuthentication]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ["medicalProfileId"]
    lookup_field = "id"
    queryset = GrowthTracker.objects.all()
    serializer_class = GrowthTrackerSerializer


class GrowthTrackerListDashboardView(generics.ListCreateAPIView):
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ["medicalProfileId"]
    pagination_class = StandardSetPagination
    queryset = GrowthTracker.objects.order_by("-date")
    serializer_class = GrowthTrackerSerializer


class GrowthTrackerDetailDashboardView(generics.RetrieveUpdateDestroyAPIView):
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ["medicalProfileId"]
    lookup_field = "id"
    queryset = GrowthTracker.objects.all()
    serializer_class = GrowthTrackerSerializer


class DiaperTrackerTypeListMobileView(generics.ListAPIView):
    authentication_classes = [APIKeyAuthentication]
    queryset = DiaperTrackerType.objects.all()
    serializer_class = DiaperTrackerTypeSerializer


class DiaperTrackerTypeListDashboardView(generics.ListCreateAPIView):
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = DiaperTrackerType.objects.all()
    serializer_class = DiaperTrackerTypeSerializer


class DiaperTrackerTypeDetailDashboardView(
    generics.RetrieveUpdateDestroyAPIView
):
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = DiaperTrackerType.objects.all()
    lookup_field = "id"
    serializer_class = DiaperTrackerTypeSerializer


class DiaperTrackerTypeLanguageListDashboardView(generics.ListCreateAPIView):
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = DiaperTrackerTypeLanguage.objects.all()
    serializer_class = DiaperTrackerTypeLanguageSerializer


class DiaperTrackerTypeLanguageDetailDashboardView(
    generics.RetrieveUpdateDestroyAPIView
):
    authentication_classes = [APIKeyAuthentication, DashboardTokenAuthentication]
    queryset = DiaperTrackerTypeLanguage.objects.all()
    lookup_field = "id"
    serializer_class = DiaperTrackerTypeLanguageSerializer


class DiaperTrackerGroupListMobileView(
    SubscriptionPlanMixin, generics.ListCreateAPIView
):
    authentication_classes = [APIKeyAuthentication, MobileTokenAuthentication]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ["medicalProfileId"]
    pagination_class = StandardSetPagination
    queryset = DiaperTrackerGroup.objects.order_by("-date", "-time")
    serializer_class = DiaperTrackerGroupSerializer


class DiaperTrackerGroupDetailMobileView(
    SubscriptionPlanMixin, generics.DestroyAPIView
):
    authentication_classes = [APIKeyAuthentication, MobileTokenAuthentication]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ["medicalProfileId"]
    lookup_field = "id"
    queryset = DiaperTrackerGroup.objects.all()
    serializer_class = DiaperTrackerGroupSerializer


class DiaperTrackerRowListMobileView(generics.ListCreateAPIView):
    authentication_classes = [APIKeyAuthentication, MobileTokenAuthentication]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ["diaperTrackerGroupId", "diaperTrackerTypeId"]
    queryset = DiaperTrackerRow.objects.all()
    serializer_class = DiaperTrackerRowSerializer


class DiaperTrackerRowDetailMobileView(generics.DestroyAPIView):
    authentication_classes = [APIKeyAuthentication, MobileTokenAuthentication]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ["diaperTrackerGroupId", "diaperTrackerTypeId"]
    lookup_field = "id"
    queryset = DiaperTrackerRow.objects.all()
    serializer_class = DiaperTrackerRowSerializer
