from django.conf import settings
from django.core.cache import cache
from django.db.models import Count, Q
from django.db.models.query import QuerySet
from django.http import request
from django.shortcuts import render
from django.utils import timezone
from rest_framework import status
from rest_framework.decorators import action, permission_classes
from rest_framework.exceptions import PermissionDenied
from rest_framework.mixins import CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet, ModelViewSet
from utils.pagination import PageOrNot

from apps.system.mixins import CreateUpdateCustomMixin, CreateUpdateModelAMixin, OptimizationMixin
from apps.system.models import Organization
from apps.system.permission import get_permission_list, has_permission
from apps.system.permission_data import RbacFilterSet

from .models import *
from .serializers import *
# Create your views here.
class RegulatoryViewSet(OptimizationMixin, PageOrNot, CreateUpdateModelAMixin, ModelViewSet):
    perms_map = {'get': '*', 'post': 'regulatory_create',
                 'put': 'regulatory_update', 'delete': 'regulatory_delete'}
    queryset =  Regulatory.objects.all()
    serializer_class = RegulatorySerializer
    ordering = ['-id']
    search_fields = ['provinces']
    ordering_fields = ['provinces']
    filterset_fields = ['provinces']
class ProfessionalViewSet(OptimizationMixin, PageOrNot, CreateUpdateModelAMixin, ModelViewSet):
    perms_map = {'get': '*', 'post': 'professional_create',
                 'put': 'professional_update', 'delete': 'professional_delete'}
    queryset =  Professional.objects.all()
    serializer_class = ProfessionalSerializer
    ordering = ['-id']
class PolicyViewSet(OptimizationMixin, PageOrNot, CreateUpdateModelAMixin, ModelViewSet):
    perms_map = {'get': '*', 'post': 'policy_create',
                 'put': 'policy_update', 'delete': 'policy_delete'}
    queryset = Policy.objects.all()
    serializer_class = PolicySerializer
    ordering = ['-id']
class ValidationViewSet(OptimizationMixin, PageOrNot, CreateUpdateModelAMixin, ModelViewSet):
    perms_map = {'get': '*', 'post': 'validation_create',
                 'put': 'policy_update', 'delete': 'validation_delete'}
    queryset = Validation.objects.all()
    serializer_class = ValidationSerializer
    ordering = ['-id']
    search_fields = ['provinces']
    ordering_fields = ['provinces']
    filterset_fields = ['provinces']
