package tech.easyflow.ai.easyagentsflow.service;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Component
public class CodeEngineCapabilityService {

    private volatile boolean pythonAvailable = false;
    private volatile String pythonReason = "Python 引擎未初始化";

    public void setPythonCapability(boolean available, String reason) {
        this.pythonAvailable = available;
        this.pythonReason = reason;
    }

    public List<Map<String, Object>> listSupportedCodeEngines() {
        List<Map<String, Object>> result = new ArrayList<>();
        result.add(toItem("js", "JavaScript", true, ""));
        result.add(toItem("python", "Python", pythonAvailable, pythonAvailable ? "" : pythonReason));
        return result;
    }

    private Map<String, Object> toItem(String value, String label, boolean available, String reason) {
        Map<String, Object> item = new LinkedHashMap<>();
        item.put("value", value);
        item.put("label", label);
        item.put("available", available);
        item.put("reason", reason);
        return item;
    }
}
