import { Inspectable } from '../highlighter/inspectable.js';
import { Position } from './position.js';
import { Range } from './range.js';

export const enum Type {
    DOCTYPE = 'DOCTYPE',
    StartTag = 'start tag',
    EndTag = 'end tag',
    Comment = 'comment',
    Character = 'character',
    EndOfFile = 'end-of-file'
}

export const REPLACEMENT_CHARACTER = '\uFFFD';

export abstract class Token extends Inspectable {
    #type: Type;
    #range!: Range;

    protected constructor(type: Type) {
        super();

        this.#type = type;

        // @ts-expect-error
        this.#range = {};
    }

    public startingAt(position: Position): this {
        this.#range.start = position.copy();

        return this;
    }

    public endingAt(position: Position): this {
        this.#range.end = position.copy();

        return this;
    }

    public at(position: Position): this {
        this.#range.start = position.copy();
        this.#range.end = position.copy();

        return this;
    }

    public get range(): Range {
        return this.#range;
    }

    public get type(): Type {
        return this.#type;
    }
}
