package ch.usi.inf.sp.callgraph.renderer;

import java.util.Map;
import java.util.Objects;

public class DotMethodNode implements DotNode {

    private static final String METHOD_COLOR = "lightgreen";
    private final MethodLike method;

    public DotMethodNode(MethodLike method) {
        this.method = method;
    }

    public MethodLike getMethodLike() {
        return method;
    }

    @Override
    public Map<String, String> getProperties() {
        return Map.of(
                "shape", "rectangle",
                "style", "filled",
                "fillcolor", METHOD_COLOR,
                "label", String.format("%s\\n%s", method.getDeclaringClass(), method.prettyName())
        );
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DotMethodNode that = (DotMethodNode) o;
        return Objects.equals(method, that.method);
    }

    @Override
    public int hashCode() {
        return Objects.hash(method);
    }
}
