import json
import sys
import os

# 导入utils
from jingrow.utils.jingrow_api import get_record

def execute(context=None, inputs=None, config=None, **kwargs):
    if context is None:
        context = kwargs.get("context", {})
    if inputs is None:
        inputs = kwargs.get("inputs", {})
    if config is None:
        config = kwargs.get("config", {})
 
    # jingrow.log_error("input_record 节点 inputs汇总", f"inputs={inputs}, config={config}, context={context}")

    pagetype = inputs.get("pagetype") if isinstance(inputs, dict) else None
    name = inputs.get("name") if isinstance(inputs, dict) else None
    if not (pagetype and name):
        pagetype = (config or {}).get("pagetype") if isinstance(config, dict) else None
        name = (config or {}).get("name") if isinstance(config, dict) else None
    if not pagetype or not name:
        return {"success": False, "error": "缺少pagetype或name"}
    try:
        api_res = get_record(pagetype, name)
        if not api_res.get("success"):
            return {"success": False, "error": api_res.get("error", "获取记录失败")}
        data = api_res.get("data") or {}
        if isinstance(data, dict):
            data["success"] = True
            return data
        return {"success": True, "data": data}
    except Exception as e:
        return {"success": False, "error": str(e)} 