import { Instrument } from './instrument.js';
class SubModule {
    constructor(root) {
        this.root = root;
    }
    addMethod(name, cbName) {
        this.root[name] = cbName;
    }
    addModule(name) {
        const root = {};
        this.root[name] = root;
        const subModule = new SubModule(root);
        return subModule;
    }
}
export class AppModule {
    static get id() {
        throw new Error('No id defined');
    }
    static transformLegacy(app) { }
    constructor(output) {
        this.output = output;
        this.lifecycle = {};
        this.methods = {};
        this.symbols = [];
        this.rootModule = new SubModule(this.methods);
    }
    getSymbols() {
        return this.symbols;
    }
    addMethod(name, cbName) {
        if (typeof cbName === 'function') {
            this.rootModule.addMethod(name, cbName);
        }
        else if (typeof this[cbName] === 'function') {
            this.rootModule.addMethod(name, this[cbName].bind(this));
        }
        else {
            this.rootModule.addMethod(name, this[cbName]);
        }
    }
    addModule(name) {
        return this.rootModule.addModule(name);
    }
    instrumentize(fullPath, method) {
        const instrument = new Instrument(fullPath, this.methods, method);
        return instrument;
    }
    addLifecycleStep(name, cbName) {
        this.lifecycle[name] = this[cbName].bind(this);
    }
    executeLifecycleStep(name) {
        if (name === 'start') {
            this.isRunning = true;
        }
        else if (name === 'stop') {
            this.isRunning = false;
        }
        if (typeof this.lifecycle[name] === 'function') {
            this.lifecycle[name].call(this);
        }
    }
}
export default AppModule;
//# sourceMappingURL=app-module.js.map