from typing import List
from rest_framework.viewsets import ModelViewSet
from apps.plan.serializers import MemberSerializer
from logging import setLoggerClass
from utils import queryset
from rest_framework.views import APIView
from rest_framework.generics import ListAPIView
from apps.system.models import Dict
from apps.system.permission_data import RbacFilterSet
from apps.system.mixins import CreateUpdateCustomMixin, OptimizationMixin
import random
from rest_framework.decorators import action
from utils.pagination import PageOrNot
from apps.project.models import Project
from apps.project.filters import ProjectFilter
from apps.audit.serializers import *



class MyAuditTaskList(ListAPIView):
    """
    我的审核项目
    """
    perms_map = {'get': 'myaudittask_view'}
    serializer_class = ProjectSerializerX
    filterset_class = ProjectFilter
    search_fields = ['auditee__name', 'plan__name']
    ordering=['-pk']

    def get_queryset(self):
        queryset = Project.objects.filter(certapp_project__member_certapp__user=self.request.user)
        if hasattr(self.get_serializer_class(), 'setup_eager_loading'):
            queryset = self.get_serializer_class().setup_eager_loading(queryset)
        return queryset

# class AuditNumberViewSet(CreateUpdateCustomMixin, ModelViewSet):
#     perms_map = {'get': 'myaudittask_view'}
#     serializer_class = ProjectSerializerX
#     filterset_class = ProjectFilter
#     search_fields = ['auditee__name', 'plan__name']
#     ordering=['-pk']
class MyAuditCertappList(PageOrNot, ListAPIView):
    """
    我的审核业务
    """
    perms_map = {'get': 'myaudittask_view'}
    serializer_class = CertappSerializerX
    filterset_fields = ['project']
    ordering=['-pk']

    def get_queryset(self):
        queryset = CertApp.objects.filter(member_certapp__user=self.request.user)
        if hasattr(self.get_serializer_class(), 'setup_eager_loading'):
            queryset = self.get_serializer_class().setup_eager_loading(queryset)
        return queryset