package com.graphtest.model;

import java.util.Objects;

public class Edge {
    private final Node source;
    private final Node target;
    private final boolean selfLoop;
    private final EdgeType edgeType;

    public Edge(Node source, Node target) {
        this(source, target, EdgeType.IMPORT);
    }

    public Edge(Node source, Node target, EdgeType edgeType) {
        this.source = source;
        this.target = target;
        this.selfLoop = source.equals(target);
        this.edgeType = edgeType;
    }

    public Node getSource() { return source; }
    public Node getTarget() { return target; }
    public boolean isSelfLoop() { return selfLoop; }
    public EdgeType getEdgeType() { return edgeType; }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Edge)) return false;
        Edge edge = (Edge) o;
        return Objects.equals(source, edge.source)
            && Objects.equals(target, edge.target)
            && edgeType == edge.edgeType;
    }

    @Override
    public int hashCode() { return Objects.hash(source, target, edgeType); }

    @Override
    public String toString() {
        return source.getClassName() + " -[" + edgeType + "]-> " + target.getClassName();
    }
}
