from rest_framework.generics import (
    ListAPIView,
    RetrieveAPIView,
    CreateAPIView
)
from rest_framework.views import APIView

from rest_framework.permissions import IsAuthenticated
from rest_framework.filters import SearchFilter, OrderingFilter
from mosquito.api.pagination import PostLimitOffsetPagination, PostPageNumberPagination
from .serializers import DeviceCountSerializer, DeviceInfoSerializer
from ..models import DeviceCount, DeviceInfo


class DeviceLogListAPIView(ListAPIView):
    serializer_class = DeviceCountSerializer
    permission_classes = [IsAuthenticated]
    filter_backends = [SearchFilter, OrderingFilter]
    pagination_class = PostPageNumberPagination
    search_fields = ['device_id']
    queryset = DeviceCount.objects.get_queryset().order_by('-data_time')


class DeviceInfoListAPIView(ListAPIView):
    serializer_class = DeviceInfoSerializer
    permission_classes = [IsAuthenticated]
    filter_backends = [SearchFilter, OrderingFilter]
    pagination_class = PostPageNumberPagination
    search_fields = ['device_id', 'device_name', 'chip_type', 'chip_id']
    queryset = DeviceInfo.objects.all()


# class DeviceLogStatisticAPIView(APIView):
#     pass