const wrapper = require('bindings')('aslsp-native');

export enum MessageType{
    Error = 0,
    Warning = 1,
    Information = 2
}

export interface Message{
    section: string,
    row: number,
    col: number,
    type: number,
    message: string
}

export interface ScriptDatabase {
    reset() : void;
    loadScript(name: string, script: string): void;

    build(): number;

    messages(): Message[];
}

export function BuildDatabase() : ScriptDatabase{
    return new wrapper.Database();
}

export function testRun() : void{
    const db = module.exports.BuildDatabase();
    db.loadScript("m.as", "int foo(){return 10}");
    db.build();
    let messages = db.messages();
    console.log("Build 1");
    for (let i = 0; i < messages.length; i++) {
        console.log(messages[i]);
    }

    db.loadScript("m.as", "int foo(){return 10;}");
    db.build();
    messages = db.messages();
    console.log("Build 2");
    for (let i = 0; i < messages.length; i++) {
        console.log(messages[i]);
    }

    db.reset();
    db.loadScript("m.as", "int foo(){return 10}");
    db.build();
    messages = db.messages();
    console.log("Build 3");
    for (let i = 0; i < messages.length; i++) {
        console.log(messages[i]);
    }

}


