package cn.stylefeng.workflow.instance.core.actions.gateway;


import cn.stylefeng.workflow.api.entity.design.Node;
import cn.stylefeng.workflow.api.entity.instance.RuntimeNode;
import cn.stylefeng.workflow.api.enums.NodeTypeEnum;
import cn.stylefeng.workflow.api.pojo.InstanceContext;
import cn.stylefeng.workflow.instance.api.node.NodeAction;
import cn.stylefeng.workflow.instance.api.pojo.NodeActionResult;
import cn.stylefeng.workflow.instance.core.path.NodePathCalc;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ConditionGatewayNodeAction extends NodeAction {

    @Override
    public NodeTypeEnum getNodeType() {
        return NodeTypeEnum.CONDITION_GATEWAY;
    }

    @Override
    public NodeActionResult doAction(Node nodeInfo, InstanceContext instanceContext) {

        RuntimeNode runtimeNode = super.createAndSaveRuntimeNode(nodeInfo, instanceContext);

        List<Node> nextConditionsNodeList = new NodePathCalc(instanceContext).calcNextConditionNodeList(nodeInfo.getNodeId());

        return new NodeActionResult(runtimeNode, nextConditionsNodeList, instanceContext.getInstanceVariable());
    }

}
