package de.dhbwstuttgart.target.tree.type;

import java.util.List;
import java.util.Objects;

public record TargetRefType(String name, List<TargetType> params) implements TargetSpecializedType {
    public TargetRefType(String name) {
        this(name, List.of());
    }

    public String getInternalName() {
        return this.name.replaceAll("\\.", "/");
    }

    // Type erasure means we need to override hashCode and equals to only consider the name
    @Override
    public int hashCode() {
        return Objects.hashCode(name);
    }

    @Override
    public boolean equals(Object other) {
        if (other instanceof TargetRefType refType) {
            return refType.name.equals(name);
        }
        return false;
    }

    @Override
    public String toString() {
        if (params.isEmpty()) return name;
        else return name + "<" + java.lang.String.join(", ", params.stream().map(java.lang.Object::toString).toList()) + ">";
    }
}
