from rest_framework.viewsets import ReadOnlyModelViewSet

from apps.common.api import TeamScopedViewSetMixin

from .models import AITask, ModelConfig
from .serializers import AITaskSerializer, ModelConfigSerializer


class AITaskViewSet(TeamScopedViewSetMixin, ReadOnlyModelViewSet):
    queryset = AITask.objects.select_related("team", "project", "model_config", "model_config__provider").all()
    serializer_class = AITaskSerializer
    search_fields = ["idempotency_key", "provider_task_id", "project__name"]
    ordering_fields = ["created_at", "updated_at", "completed_at"]


class ModelConfigViewSet(ReadOnlyModelViewSet):
    queryset = ModelConfig.objects.select_related("provider").filter(status=ModelConfig.Status.ACTIVE)
    serializer_class = ModelConfigSerializer
    search_fields = ["name", "display_name", "capability"]
    ordering_fields = ["created_at", "display_name"]

