package com.cmvr.test.flow.builder;

import java.util.List;
import java.util.stream.Collectors;

public class TaskKeyBuilder {

    /**
     * 创建scheduleCache key
     */
    public static String buildKey(String instId, String nodeId, List<Integer> iterations) {
        StringBuilder sb = new StringBuilder(instId).append(":").append(nodeId);
        for (int it : iterations) {
            sb.append(":").append(it);
        }
        return sb.toString();
    }

    /**
     * 线程注册-节点执行上下文key
     */
    public static String buildKey(String instId, String itemId, String nodeId) {
        return instId + "_" + itemId + "_" + nodeId;
    }

    /**
     * 线程注册-loop节点执行上下文key
     */
    public static String buildLoopKey(String instId, String nodeId) {
        return instId + "_" + nodeId;
    }

    /**
     * 节点输出参数 key
     */
    public static String buildKey(String nodeId, List<Integer> iterations) {
        return nodeId + "@" + iterations.stream()
                .map(String::valueOf)
                .collect(Collectors.joining("."));
    }
}
