package p.studio.compiler.source.identifiers;

import lombok.EqualsAndHashCode;
import lombok.Getter;

@Getter
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public abstract class SourceIdentifier {
    @EqualsAndHashCode.Include
    private final int id;

    public SourceIdentifier(int id) {
        this.id = id;
    }

    public int getIndex() {
        if (id < 0) {
            throw new IllegalArgumentException("index should be valid (positive)");
        }
        return id;
    }

    @Override
    public String toString() {
        return String.format("%s(%d)", getClass().getSimpleName(), id);
    }
}
