from rest_framework import viewsets
from ces_fall_rest_api.models.outcome import Outcome
from ces_fall_rest_api.serializers.outcome_serializer import OutcomeSerializer
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import action
from rest_framework.response import Response

from ces_fall_rest_api.models.major import Major
from ces_fall_rest_api.serializers.major_serializer import MajorSerializer


class MajorViewSet(viewsets.ModelViewSet):
    """A simple viewset to get the all the Major objects
    This class has a token authentication.

    Args:
        viewsets (_type_): viewsets class
    """
    queryset = Major.objects.all()
    serializer_class = MajorSerializer
    permission_classes = [IsAuthenticated]

    def get_object(self):
        lookup_args = ['degree', 'subject_area']

        if all(arg in self.kwargs for arg in lookup_args):
            return Major.objects.get(degree=self.kwargs['degree'].strip(), subject_area=self.kwargs['subject_area'].strip())
        else:
            return super().get_object()
