/**
 * UI服务注册中心
 *
 * @export
 * @class UIServiceRegister
 */
export class UIServiceRegister {

    /**
     * 所有UI实体服务Map
     *
     * @protected
     * @type {*}
     * @memberof UIServiceRegister
     */
    protected allUIService: Map<string, () => Promise<any>> = new Map();

    /**
     * 已加载UI实体服务Map缓存
     *
     * @protected
     * @type {Map<string, any>}
     * @memberof UIServiceRegister
     */
    protected serviceCache: Map<string, any> = new Map();

    /**
     * Creates an instance of UIServiceRegister.
     * @memberof UIServiceRegister
     */
    constructor() {
        this.init();
    }

    /**
     * 初始化
     *
     * @protected
     * @memberof UIServiceRegister
     */
    protected init(): void {
                this.allUIService.set('userrole', () => import('@/uiservice/user-role/user-role-ui-service'));
        this.allUIService.set('orguser', () => import('@/uiservice/org-user/org-user-ui-service'));
        this.allUIService.set('usergroupdetail', () => import('@/uiservice/user-group-detail/user-group-detail-ui-service'));
        this.allUIService.set('userroledatascope', () => import('@/uiservice/user-role-data-scope/user-role-data-scope-ui-service'));
        this.allUIService.set('unires', () => import('@/uiservice/uni-res/uni-res-ui-service'));
        this.allUIService.set('org', () => import('@/uiservice/org/org-ui-service'));
        this.allUIService.set('dataentity', () => import('@/uiservice/data-entity/data-entity-ui-service'));
        this.allUIService.set('application', () => import('@/uiservice/application/application-ui-service'));
        this.allUIService.set('userobject', () => import('@/uiservice/user-object/user-object-ui-service'));
        this.allUIService.set('usergroup', () => import('@/uiservice/user-group/user-group-ui-service'));
        this.allUIService.set('userroledataaction', () => import('@/uiservice/user-role-data-action/user-role-data-action-ui-service'));
        this.allUIService.set('userroledetail', () => import('@/uiservice/user-role-detail/user-role-detail-ui-service'));
        this.allUIService.set('orgdept', () => import('@/uiservice/org-dept/org-dept-ui-service'));
        this.allUIService.set('userroletype', () => import('@/uiservice/user-role-type/user-role-type-ui-service'));
        this.allUIService.set('userroledata', () => import('@/uiservice/user-role-data/user-role-data-ui-service'));
        this.allUIService.set('userroleres', () => import('@/uiservice/user-role-res/user-role-res-ui-service'));
        this.allUIService.set('orgdeptuser', () => import('@/uiservice/org-dept-user/org-dept-user-ui-service'));
        this.allUIService.set('user', () => import('@/uiservice/user/user-ui-service'));
        this.allUIService.set('system', () => import('@/uiservice/system/system-ui-service'));
        this.allUIService.set('loginaccountpwd', () => import('@/uiservice/login-account-pwd/login-account-pwd-ui-service'));
        this.allUIService.set('userroledatas', () => import('@/uiservice/user-role-datas/user-role-datas-ui-service'));
        this.allUIService.set('loginaccount', () => import('@/uiservice/login-account/login-account-ui-service'));
    }

    /**
     * 加载服务实体
     *
     * @protected
     * @param {string} serviceName
     * @returns {Promise<any>}
     * @memberof UIServiceRegister
     */
    protected async loadService(serviceName: string): Promise<any> {
        const service = this.allUIService.get(serviceName);
        if (service) {
            return service();
        }
    }

    /**
     * 获取应用实体服务
     *
     * @param {string} name
     * @returns {Promise<any>}
     * @memberof UIServiceRegister
     */
    public async getService(name: string): Promise<any> {
        if (this.serviceCache.has(name)) {
            return this.serviceCache.get(name);
        }
        const entityService: any = await this.loadService(name);
        if (entityService && entityService.default) {
            const instance: any = new entityService.default();
            this.serviceCache.set(name, instance);
            return instance;
        }
    }

}
export const uiServiceRegister: UIServiceRegister = new UIServiceRegister();