from rest_framework.permissions import IsAuthenticated
from rest_framework.views import APIView
from rest_framework_simplejwt.authentication import JWTAuthentication

from module_project import constants
from module_project.utils import ApiResponse

from ..models import Faqs, Organization
from .serializers import FaqSerializer, OrganizationSerializer


class FaqListAPIView(APIView):
    authentication_classes = [JWTAuthentication]
    permission_classes = [IsAuthenticated]
    serializer_class = FaqSerializer
    model = Faqs

    def get(self, request):
        queryset = self.model.objects.filter(active=True)
        serializer = self.serializer_class(queryset, many=True)
        return ApiResponse.success(message=constants.SUCCESS, data=serializer.data)

class OrganizationAPIView(APIView):
    authentication_classes = []
    permission_classes = []
    serializer_class = OrganizationSerializer
    model = Organization

    def get(self, request):
        queryset = self.model.objects.filter(active=True).last()
        serializer = self.serializer_class(queryset)
        return ApiResponse.success(message=constants.SUCCESS, data=serializer.data)
