import { VERIFY } from '../../../util/assertions.js';
import { Token, Type, REPLACEMENT_CHARACTER } from '../token.js';

export class DOCTYPEToken extends Token {
    public name?: string;
    public publicIdentifier?: string;
    public systemIdentifier?: string;
    public forceQuirks?: true;

    public constructor(name?: string, publicIdentifier?: string, systemIdentifier?: string, forceQuirks?: true) {
        super(Type.DOCTYPE);

        this.name = name;
        this.publicIdentifier = publicIdentifier;
        this.systemIdentifier = systemIdentifier;
        this.forceQuirks = forceQuirks;
    }

    public appendToName(characters: string): void {
        VERIFY(this.name !== undefined);

        this.name += characters;
    }

    public appendReplacementCharacterToName(): void {
        this.appendToName(REPLACEMENT_CHARACTER);
    }

    public setForceQuirks(): void {
        this.forceQuirks = true;
    }

    public static createWithForcedQuirks(): DOCTYPEToken {
        return new DOCTYPEToken(undefined, undefined, undefined, true);
    }

    public static createWithName(name: string): DOCTYPEToken {
        return new DOCTYPEToken(name, undefined, undefined, undefined);
    }

    public static createWithReplacementCharacter(): DOCTYPEToken {
        return new DOCTYPEToken(REPLACEMENT_CHARACTER, undefined, undefined, undefined);
    }

    public override inspect(indent: number): string {
        return `DOCTYPEToken { '${this.name}' }`;
    }
}
