package leigh.mecha.nodegraph;

import java.util.Objects;

/**
 * POJO containing information about a connection between two nodes.
 *
 * @author Alex Leigh
 */
public class NodeConnection {
    private final NodeObject srcNode;
    private final NodeObject dstNode;
    private final NodeAttribute srcAttribute;
    private final NodeAttribute dstAttribute;

    public NodeConnection(NodeObject srcNode, NodeAttribute srcAttribute,
                          NodeObject dstNode, NodeAttribute dstAttribute) {
        this.srcNode = srcNode;
        this.dstNode = dstNode;
        this.srcAttribute = srcAttribute;
        this.dstAttribute = dstAttribute;
    }

    public NodeObject getSrcNode() {
        return srcNode;
    }

    public NodeObject getDstNode() {
        return dstNode;
    }

    public NodeAttribute getSrcAttribute() {
        return srcAttribute;
    }

    public NodeAttribute getDstAttribute() {
        return dstAttribute;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        NodeConnection that = (NodeConnection) o;
        return Objects.equals(srcNode, that.srcNode) &&
                Objects.equals(dstNode, that.dstNode) &&
                Objects.equals(srcAttribute, that.srcAttribute) &&
                Objects.equals(dstAttribute, that.dstAttribute);
    }

    @Override
    public int hashCode() {
        return Objects.hash(srcNode, dstNode, srcAttribute, dstAttribute);
    }

    @Override
    public String toString() {
        return "NodeConnection{" +
                "srcNode=" + srcNode.getId() +
                ", dstNode=" + dstNode.getId() +
                ", srcAttribute=" + srcAttribute +
                ", dstAttribute=" + dstAttribute +
                '}';
    }
}
