/**
 * Copyright (c) 2025-2026, Michael Yang 杨福海 (fuhai999@gmail.com).
 * <p>
 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.easyagents.flow.core.code;

import com.easyagents.flow.core.chain.Chain;
import com.easyagents.flow.core.node.CodeNode;

import java.util.Map;

/**
 * 代码节点运行时引擎。
 */
public interface CodeRuntimeEngine {

    /**
     * 执行代码节点。
     *
     * @param code 解析模板后的代码
     * @param node 当前代码节点
     * @param chain 当前工作流
     * @return 节点输出
     */
    Map<String, Object> execute(String code, CodeNode node, Chain chain);

    /**
     * 使用已经解析的节点参数执行代码。
     *
     * <p>默认委托旧接口，保持自定义运行时引擎兼容。内置引擎可覆盖该方法，
     * 避免重复解析节点参数。</p>
     *
     * @param code 解析模板后的代码
     * @param node 当前代码节点
     * @param chain 当前工作流
     * @param parameterValues 已解析的节点参数
     * @return 节点输出
     */
    default Map<String, Object> execute(String code,
                                        CodeNode node,
                                        Chain chain,
                                        Map<String, Object> parameterValues) {
        return execute(code, node, chain);
    }
}
