from rest_framework import serializers

from .models import AITask, ModelConfig, ModelProvider


class ModelProviderSerializer(serializers.ModelSerializer):
    class Meta:
        model = ModelProvider
        fields = ["id", "name", "display_name", "status", "base_url", "metadata"]
        read_only_fields = fields


class ModelConfigSerializer(serializers.ModelSerializer):
    provider = ModelProviderSerializer(read_only=True)

    class Meta:
        model = ModelConfig
        fields = ["id", "provider", "name", "display_name", "capability", "endpoint", "unit_price", "status", "metadata"]
        read_only_fields = fields


class AITaskSerializer(serializers.ModelSerializer):
    model_config = ModelConfigSerializer(read_only=True)

    class Meta:
        model = AITask
        fields = [
            "id",
            "project",
            "task_type",
            "status",
            "model_config",
            "provider_task_id",
            "estimated_cost",
            "actual_cost",
            "error_code",
            "error_message",
            "submitted_at",
            "completed_at",
            "created_at",
            "updated_at",
        ]
        read_only_fields = fields

