"""
API响应工具模块
用于处理API响应数据的转换
"""
from typing import Dict, Any, List, Optional
from data.models.task_instance import TaskInstance
from data.models.task_input_param import TaskInputParam

class ApiResponseUtil:
    """API响应工具类"""
    
    @staticmethod
    def to_task_instance_response(instance: TaskInstance) -> Optional[Dict[str, Any]]:
        """
        将任务实例转换为API响应数据
        
        Args:
            instance: 任务实例对象
            
        Returns:
            API响应数据字典
        """
        if not instance:
            return None
            
        return {
            "instance_id": instance.instance_id,
            "task_id": instance.task_id,
            "name": instance.name,
            "variables": instance.variables or {},
            "priority": instance.priority,
            "block_outputs": instance.block_outputs or {},
            "context_params": instance.context_params or {},
            "status": instance.status.value if instance.status else None
        }
    
    @staticmethod
    def to_task_input_param_response(param: TaskInputParam) -> Optional[Dict[str, Any]]:
        """
        将任务输入参数转换为API响应数据
        
        Args:
            param: 任务输入参数对象
            
        Returns:
            API响应数据字典
        """
        if not param:
            return None
            
        return {
            "param_id": param.param_id,
            "param_name": param.param_name,
            "label": param.label,
            "param_type": param.param_type,
            "required": param.required,
            "default_value": param.default_value,
            "description": param.description,
            "is_system": param.is_system,
            "is_readonly": param.is_readonly,
            "sort_order": param.sort_order
        } 