package xyz.ignatz.flowchart.module;

import org.apache.commons.lang.StringEscapeUtils;

import java.util.*;

public class Node implements INode {
    String label;
    Integer line;
    Map<String, Node> tps;

    public Node(String label, Integer line, Map<String, Node> tps) {
        tps.remove(null);
        this.label = label;
        this.line = line;
        this.tps = tps;
    }

    public boolean connect(Node dst, String label) {
        Objects.requireNonNull(label);
        if (tps.containsKey(label) && tps.get(label) == null) {
            tps.put(label, dst);
            return true;
        }
        return false;
    }

    public String html() {
        return StringEscapeUtils.escapeHtml(label) + "<i><font color=\"gray\">  " + line.toString() +"</font></i>";
    }

    public Map<String, INode> links() {
        return new HashMap<>(tps);
    }
}
