from rest_framework.generics import ListAPIView
from service.models.services import Services, ServicesCategory
from service.serializers.summary_service_serializer import ServiceSummarySerializer
from common.pagination.custom_pagination import CustomPageNumberPagination
from rest_framework.exceptions import NotFound

class FilteredServicesByCategory(ListAPIView):
    serializer_class = ServiceSummarySerializer
    pagination_class = CustomPageNumberPagination

    def get_queryset(self):
        category = self.kwargs.get('category', '').upper()

        # Map string to IntegerChoice
        try:
            category_value = ServicesCategory[category].value
        except KeyError:
            raise NotFound(detail=f"Invalid service category '{category}'. Use one of {[c.name for c in ServicesCategory]}")
        
        return Services.objects.filter(service_category=category_value, is_active=True)