package cd.casic.ci.process.process.service.variable.impl;

import cd.casic.ci.process.engine.constant.AFLSlotCompileConstant;
import cd.casic.ci.process.engine.manager.RunContextManager;
import cd.casic.ci.process.engine.runContext.BaseRunContext;
import cd.casic.ci.process.process.service.variable.VariableService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class VariableServiceImpl implements VariableService {
    @Resource
    private RunContextManager contextManager;
    @Override
    public Object getPipelineContextGlobalVariable(String pipelineId, String varName) {
        BaseRunContext context = contextManager.getContext(pipelineId);
        if (context== null) {
            return "";
        }
        Map<String, Object> globalVariables = context.getGlobalVariables();
        log.info("当前全局变量：{}",globalVariables);
        return globalVariables.get(varName);
    }

    @Override
    public Map<String,Object> getPipelineContextGlobalVariables(String pipelineId) {
        BaseRunContext context = contextManager.getContext(pipelineId);
        if (context== null) {
            return new HashMap<>();
        }
        Map<String, Object> globalVariables = context.getGlobalVariables();
        log.info("当前全局变量：{}",globalVariables);
        return globalVariables;
    }
}
