package p.studio.compiler.source;

import lombok.Getter;
import p.studio.compiler.source.identifiers.FileId;

@Getter
public class Span {
    private final FileId fileId;
    private final long start;
    private final long end; // exclusive

    public Span(FileId fileId, long start, long end) {
        this.fileId = fileId;
        this.start = Math.min(start, end);
        this.end = Math.max(start, end);
    }

    public static Span none() {
        return new Span(FileId.none(), 0, 0);
    }

    public boolean isNone() {
        return fileId.isNone();
    }

    public long length() {
        return end - start;
    }

    public boolean contains(long pos) {
        if (pos < 0L) return false;
        return start <= pos && end > pos;
    }
}
