#include events.js

const MamiContext = function(globalEventTarget, eventTarget) {
    if(typeof globalEventTarget !== 'object' && globalEventTarget === null)
        throw 'globalEventTarget must be undefined or a non-null object';

    if(eventTarget === undefined)
        eventTarget = 'mami';
    else if(typeof eventTarget !== 'object' || eventTarget === null)
        throw 'eventTarget must be a string or a non-null object';

    if(typeof eventTarget === 'string')
        eventTarget = globalEventTarget.scopeTo(eventTarget);

    let isUnloading = false;

    let settings;
    let msgbox;
    let views;
    let sound;
    let textTriggers;
    let eeprom;
    let conMan;
    let protoWorker;

    return {
        get globalEvents() { return globalEventTarget; },
        get events() { return eventTarget; },

        get isUnloading() { return isUnloading; },
        set isUnloading(state) {
            isUnloading = !!state;
        },

        get settings() { return settings; },
        set settings(value) {
            if(settings !== undefined)
                throw 'settings is already defined';
            if(typeof value !== 'object' || value === null)
                throw 'settings must be a non-null object';
            settings = value;
        },

        get msgbox() { return msgbox; },
        set msgbox(value) {
            if(msgbox !== undefined)
                throw 'msgbox is already defined';
            if(typeof value !== 'object' || value === null)
                throw 'msgbox must be a non-null object';
            msgbox = value;
        },

        get views() { return views; },
        set views(value) {
            if(views !== undefined)
                throw 'views is already defined';
            if(typeof value !== 'object' || value === null)
                throw 'views must be a non-null object';
            views = value;
        },

        get sound() { return sound; },
        set sound(value) {
            if(sound !== undefined)
                throw 'sound is already defined';
            if(typeof value !== 'object' || value === null)
                throw 'sound must be a non-null object';
            sound = value;
        },

        get textTriggers() { return textTriggers; },
        set textTriggers(value) {
            if(typeof value !== 'object' || value === null)
                throw 'textTriggers must be a non-null object';
            textTriggers = value;
        },

        get eeprom() { return eeprom; },
        set eeprom(value) {
            if(typeof value !== 'object' || value === null)
                throw 'eeprom must be a non-null object';
            eeprom = value;
        },

        get conMan() { return conMan; },
        set conMan(value) {
            if(typeof value !== 'object' || value === null)
                throw 'conMan must be a non-null object';
            conMan = value;
        },

        get protoWorker() { return protoWorker; },
        set protoWorker(value) {
            if(typeof value !== 'object' || value === null)
                throw 'protoWorker must be a non-null object';
            protoWorker = value;
        },
    };
};
