import { Inspectable } from '../highlighter/inspectable.js';

export class Position extends Inspectable {
    #line: number;
    #column: number;
    #index: number;

    private constructor(line: number, column: number, index: number) {
        super();

        this.#line = line;
        this.#column = column;
        this.#index = index;
    }

    public get line(): number {
        return this.#line;
    }

    public get column(): number {
        return this.#column;
    }

    public get index(): number {
        return this.#index;
    }

    public increment(by: number = 1): this {
        this.#index += by;
        this.#column += by;

        return this;
    }

    public decrement(by: number = 1): this {
        this.#index -= by;
        this.#column -= by;

        return this;
    }

    public incrementLine(): this {
        this.#line++;
        this.#column = 0;

        return this;
    }

    public copy(): Position {
        return new Position(this.line, this.column, this.index);
    }

    public static createStarting(): Position {
        return new Position(0, 0, -1);
    }

    public override inspect(indent: number): string {
        return `Position { line: ${this.#line}, column: ${this.#column}, index: ${this.#index} }`;
    }
}
