/**
 * 视图消息服务注册中心
 *
 * @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('ViewMsg2', () => import('@/message/view-msg2/view-msg2-message'));
        this.allMessageService.set('ViewMsg10', () => import('@/message/view-msg10/view-msg10-message'));
        this.allMessageService.set('ViewMsg23', () => import('@/message/view-msg23/view-msg23-message'));
        this.allMessageService.set('ViewMsg7', () => import('@/message/view-msg7/view-msg7-message'));
        this.allMessageService.set('DataViewDar', () => import('@/message/data-view-dar/data-view-dar-message'));
        this.allMessageService.set('ViewMsg17', () => import('@/message/view-msg17/view-msg17-message'));
        this.allMessageService.set('ViewMsg20', () => import('@/message/view-msg20/view-msg20-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('ViewMsg13', () => import('@/message/view-msg13/view-msg13-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('ViewMsg9', () => import('@/message/view-msg9/view-msg9-message'));
        this.allMessageService.set('ViewMsg18', () => import('@/message/view-msg18/view-msg18-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('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'));
    }

    /**
     * 加载视图消息服务
     *
     * @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();