package com.cmvr.test.flow.runtime.dispatcher;


import com.cmvr.common.exception.GlobalException;
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage;
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
@RequiredArgsConstructor
public class FlowNodeTypeDispatch {

    private final Map<String, FlowNodeTypeHandler> nodeTypeHandlerMap;

    public TaskNodeExecuteResult dispatch(TaskNodeExecuteMessage message) {
        String type = message.getNodeType();
        FlowNodeTypeHandler handler = nodeTypeHandlerMap.get(type);
        if (handler == null) {
            throw new GlobalException("不支持的节点类型: " + type);
        }

        return handler.handle(message);
    }
}
