/**
 * 视图消息服务注册中心
 *
 * @export
 * @class MessageServiceRegister
 */
export class MessageServiceRegister {

    /**
     * 所有视图消息服务Map
     *
     * @protected
     * @type {*}
     * @memberof MessageServiceRegister
     */
    protected allMessageService: Map<string, () => Promise<any>> = new Map();

    /**
     * 已加载视图消息服务Map缓存
     *
     * @protected
     * @type {Map<string, any>}
     * @memberof MessageServiceRegister
     */
    protected serviceCache: Map<string, any> = new Map();

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

    /**
     * 初始化
     *
     * @protected
     * @memberof MessageServiceRegister
     */
    protected init(): void {
                this.allMessageService.set('ViewMsg4', () => import('@/message/view-msg4/view-msg4-message'));
        this.allMessageService.set('ViewMsg22', () => import('@/message/view-msg22/view-msg22-message'));
        this.allMessageService.set('ViewMsg24', () => import('@/message/view-msg24/view-msg24-message'));
        this.allMessageService.set('ViewMsg48', () => import('@/message/view-msg48/view-msg48-message'));
        this.allMessageService.set('ViewMsg40', () => import('@/message/view-msg40/view-msg40-message'));
        this.allMessageService.set('ViewMsg53', () => import('@/message/view-msg53/view-msg53-message'));
        this.allMessageService.set('ViewMsg2', () => import('@/message/view-msg2/view-msg2-message'));
        this.allMessageService.set('ViewMsg28', () => import('@/message/view-msg28/view-msg28-message'));
        this.allMessageService.set('ViewMsg54', () => import('@/message/view-msg54/view-msg54-message'));
        this.allMessageService.set('ViewMsg10', () => import('@/message/view-msg10/view-msg10-message'));
        this.allMessageService.set('ViewMsg49', () => import('@/message/view-msg49/view-msg49-message'));
        this.allMessageService.set('ViewMsg7', () => import('@/message/view-msg7/view-msg7-message'));
        this.allMessageService.set('ViewMsg26', () => import('@/message/view-msg26/view-msg26-message'));
        this.allMessageService.set('ViewMsg23', () => import('@/message/view-msg23/view-msg23-message'));
        this.allMessageService.set('ViewMsg37', () => import('@/message/view-msg37/view-msg37-message'));
        this.allMessageService.set('ViewMsg47', () => import('@/message/view-msg47/view-msg47-message'));
        this.allMessageService.set('DataViewDar', () => import('@/message/data-view-dar/data-view-dar-message'));
        this.allMessageService.set('ViewMsg38', () => import('@/message/view-msg38/view-msg38-message'));
        this.allMessageService.set('ViewMsg17', () => import('@/message/view-msg17/view-msg17-message'));
        this.allMessageService.set('ViewMsg41', () => import('@/message/view-msg41/view-msg41-message'));
        this.allMessageService.set('ViewMsg35', () => import('@/message/view-msg35/view-msg35-message'));
        this.allMessageService.set('ViewMsg30', () => import('@/message/view-msg30/view-msg30-message'));
        this.allMessageService.set('ViewMsg32', () => import('@/message/view-msg32/view-msg32-message'));
        this.allMessageService.set('ViewMsg51', () => import('@/message/view-msg51/view-msg51-message'));
        this.allMessageService.set('ViewMsg20', () => import('@/message/view-msg20/view-msg20-message'));
        this.allMessageService.set('ViewMsg43', () => import('@/message/view-msg43/view-msg43-message'));
        this.allMessageService.set('ViewMsg15', () => import('@/message/view-msg15/view-msg15-message'));
        this.allMessageService.set('ViewMsg5', () => import('@/message/view-msg5/view-msg5-message'));
        this.allMessageService.set('ViewMsg16', () => import('@/message/view-msg16/view-msg16-message'));
        this.allMessageService.set('ViewMsg46', () => import('@/message/view-msg46/view-msg46-message'));
        this.allMessageService.set('ViewMsg42', () => import('@/message/view-msg42/view-msg42-message'));
        this.allMessageService.set('ViewMsg39', () => import('@/message/view-msg39/view-msg39-message'));
        this.allMessageService.set('ViewMsg13', () => import('@/message/view-msg13/view-msg13-message'));
        this.allMessageService.set('ViewMsg44', () => import('@/message/view-msg44/view-msg44-message'));
        this.allMessageService.set('ViewMsg45', () => import('@/message/view-msg45/view-msg45-message'));
        this.allMessageService.set('ViewMsg50', () => import('@/message/view-msg50/view-msg50-message'));
        this.allMessageService.set('ViewMsg29', () => import('@/message/view-msg29/view-msg29-message'));
        this.allMessageService.set('ViewMsg8', () => import('@/message/view-msg8/view-msg8-message'));
        this.allMessageService.set('ViewMsg', () => import('@/message/view-msg/view-msg-message'));
        this.allMessageService.set('ViewMsg27', () => import('@/message/view-msg27/view-msg27-message'));
        this.allMessageService.set('ViewMsg9', () => import('@/message/view-msg9/view-msg9-message'));
        this.allMessageService.set('ViewMsg18', () => import('@/message/view-msg18/view-msg18-message'));
        this.allMessageService.set('ViewMsg36', () => import('@/message/view-msg36/view-msg36-message'));
        this.allMessageService.set('ViewMsg52', () => import('@/message/view-msg52/view-msg52-message'));
        this.allMessageService.set('ViewMsg12', () => import('@/message/view-msg12/view-msg12-message'));
        this.allMessageService.set('ViewMsg19', () => import('@/message/view-msg19/view-msg19-message'));
        this.allMessageService.set('ViewMsg21', () => import('@/message/view-msg21/view-msg21-message'));
        this.allMessageService.set('ViewMsg11', () => import('@/message/view-msg11/view-msg11-message'));
        this.allMessageService.set('ViewMsg25', () => import('@/message/view-msg25/view-msg25-message'));
        this.allMessageService.set('ViewMsg34', () => import('@/message/view-msg34/view-msg34-message'));
        this.allMessageService.set('ViewMsg3', () => import('@/message/view-msg3/view-msg3-message'));
        this.allMessageService.set('ViewMsg6', () => import('@/message/view-msg6/view-msg6-message'));
        this.allMessageService.set('ViewMsg14', () => import('@/message/view-msg14/view-msg14-message'));
        this.allMessageService.set('ViewMsg33', () => import('@/message/view-msg33/view-msg33-message'));
        this.allMessageService.set('ViewMsg31', () => import('@/message/view-msg31/view-msg31-message'));
    }

    /**
     * 加载视图消息服务
     *
     * @protected
     * @param {string} codeName
     * @returns {Promise<any>}
     * @memberof MessageServiceRegister
     */
    protected async loadService(codeName: string): Promise<any> {
        const service = this.allMessageService.get(codeName);
        if (service) {
            return service();
        }
    }

    /**
     * 获取视图消息服务
     *
     * @param {string} name
     * @returns {Promise<any>}
     * @memberof MessageServiceRegister
     */
    public async getService(name: string): Promise<any> {
        if (this.serviceCache.has(name)) {
            return this.serviceCache.get(name);
        }
        const messageService: any = await this.loadService(name);
        if (messageService && messageService.default) {
            const instance: any = new messageService.default();
            this.serviceCache.set(name, instance);
            return instance;
        }
    }

}
export const messageServiceRegister: MessageServiceRegister = new MessageServiceRegister();