"""
SQL 执行工具 (工具 33)
"""

from ._base import register_tool, ToolDef


@register_tool("execute_sql")
class ExecuteSqlTool(ToolDef):
    name = "execute_sql"
    description = "执行原生 SQL 查询"
    input_schema = {
        "type": "object",
        "properties": {
            "datasourceId": {"type": "string", "description": "数据源 ID"},
            "executableSql": {"type": "string", "description": "SQL 语句"},
            "sqlTemplate": {"type": "string", "description": "SQL 模板（可选）"},
            "businessName": {"type": "string", "description": "业务名称（可选）"},
            "parameters": {"type": "object", "description": "参数定义（可选）"},
        },
        "required": ["datasourceId", "executableSql"],
    }

    async def execute(self, args: dict) -> dict:
        return self.client.post("/api/datasource/sqlExecutionLog/testSqlWithSchema", json_data=args)
