/*
 * Copyright (C) 2016-2020 Kano Computing Ltd.
 * License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 */
export class Meta {
    constructor(def, parent) {
        this.parent = parent;
        this.def = def;
        this.build();
    }
    disable() {
        this.def.disabled = true;
    }
    build() {
        if (!this.def.symbols) {
            return;
        }
        this.symbols = this.def.symbols.map((sym) => {
            switch (sym.type) {
                case 'variable': {
                    return new MetaVariable(sym, this);
                }
                case 'module': {
                    return new MetaModule(sym, this);
                }
                case 'function': {
                    return new MetaFunction(sym, this);
                }
                default: {
                    break;
                }
            }
            return null;
        }).filter(v => v !== null);
    }
    getNameChain(sep = '_', prev = '') {
        if (!this.parent) {
            return this.def.name;
        }
        return `${this.parent.getNameChain(sep, prev)}${sep}${this.def.name}`;
    }
    getColor() {
        if (this.def.color) {
            return this.def.color;
        }
        if (this.parent) {
            return this.parent.getColor();
        }
        return '';
    }
    getVerboseDisplay() {
        if (typeof this.def.verbose === 'undefined') {
            return this.def.name;
        }
        return this.def.verbose;
    }
    getRoot() {
        if (!this.parent) {
            return this;
        }
        return this.parent.getRoot();
    }
}
export class MetaParameter extends Meta {
    getReturnType() {
        return this.def.returnType;
    }
}
export class MetaVariable extends Meta {
    getReturnType() {
        return this.def.returnType;
    }
}
export class MetaModule extends Meta {
}
export class MetaFunction extends Meta {
    constructor(def, parent) {
        super(def, parent);
        this.def = def;
        this.parameters = (this.def.parameters || []).map(p => new MetaParameter(p, this));
    }
    getReturnType() {
        return this.def.returnType;
    }
    getParameters() {
        return this.parameters;
    }
}
export default MetaModule;
//# sourceMappingURL=module.js.map