"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,a)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const protocol_1=__importDefault(require("../protocol")),Error_1=__importStar(require("../common/Error")),i18n_1=__importDefault(require("../i18n"));class ModuleManager{constructor(){this.moduleMap=new Map,this.addEventListener=(e,t,r)=>{const o=this.moduleMap.get(e),a=protocol_1.default[e];if(!o||!a.eventNames.includes(t))throw new Error_1.default({code:Error_1.CoreErrorCode.CORE_MODULE_ERROR,message:i18n_1.default.t("CORE_MODULE_ERROR_NAME_INVALID",{name:t,moduleName:e})});return o.addEventListener(t,r)},this.execute=(e,t,...r)=>{const o=this.moduleMap.get(e),a=protocol_1.default[e];if(!o||!a.commandNames.includes(t))throw new Error_1.default({code:Error_1.CoreErrorCode.CORE_MODULE_ERROR,message:i18n_1.default.t("CORE_MODULE_ERROR_CMD_INVALID",{moduleName:e,cmd:t})});return o.exec(t,...r)}}async init(e){const t=[];for(let r=0,o=e.length;r<o;r++){const o=e[r];if(!protocol_1.default[o.moduleName])throw new Error_1.default({code:Error_1.CoreErrorCode.CORE_MODULE_ERROR,message:i18n_1.default.t("CORE_MODULE_ERROR_NOT_DECLARANT",{moduleName:o.moduleName})});t.push(o.moduleName),this.moduleMap.set(o.moduleName,o)}const r=[];for(let o=0,a=e.length;o<a;o++){const a=e[o];if(protocol_1.default[a.moduleName].dependencies.some(e=>!t.includes(e)))throw new Error_1.default({code:Error_1.CoreErrorCode.CORE_MODULE_ERROR,message:i18n_1.default.t("CORE_MODULE_ERROR_MISS_DEPENDENCY",{moduleName:a.moduleName})});r.push(a.install(this))}await r}}exports.default=ModuleManager;