namespace NubLang.Code;

public class SourceFile
{
    private string? _content;

    public SourceFile(string path)
    {
        Path = path ?? throw new ArgumentNullException(nameof(path));
    }

    public string Path { get; }

    public string GetText() => _content ??= File.ReadAllText(Path);
    public override string ToString() => Path;

    public override bool Equals(object? obj)
    {
        return obj is SourceFile other && other.Path == Path;
    }

    public override int GetHashCode()
    {
        return HashCode.Combine(typeof(SourceFile), Path);
    }

    public static bool operator ==(SourceFile? left, SourceFile? right) => Equals(left, right);
    public static bool operator !=(SourceFile? left, SourceFile? right) => !Equals(left, right);
}

public class SourceFileSpan
{
    public SourceFileSpan(SourceFile sourceFile, SourceSpan span)
    {
        SourceFile = sourceFile;
        Span = span;
    }

    public SourceFile SourceFile { get; }
    public SourceSpan Span { get; }
}