/**
 * 实体数据服务注册中心
 *
 * @export
 * @class EntityServiceRegister
 */
export class EntityServiceRegister {

    /**
     * 所有实体数据服务Map
     *
     * @protected
     * @type {*}
     * @memberof EntityServiceRegister
     */
    protected allEntityService: Map<string, () => Promise<any>> = new Map();

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

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

    /**
     * 初始化
     *
     * @protected
     * @memberof EntityServiceRegister
     */
    protected init(): void {
                this.allEntityService.set('eamlocationstatemodel', () => import('@/service/eamlocation-state-model/eamlocation-state-model-service'));
        this.allEntityService.set('eamlocationtype', () => import('@/service/eamlocation-type/eamlocation-type-service'));
        this.allEntityService.set('eamworkorder', () => import('@/service/eamwork-order/eamwork-order-service'));
        this.allEntityService.set('eamlocation', () => import('@/service/eamlocation/eamlocation-service'));
        this.allEntityService.set('eamassetstate', () => import('@/service/eamasset-state/eamasset-state-service'));
        this.allEntityService.set('eamlocationstate', () => import('@/service/eamlocation-state/eamlocation-state-service'));
        this.allEntityService.set('eamassettype', () => import('@/service/eamasset-type/eamasset-type-service'));
        this.allEntityService.set('eamassetstatemodelline', () => import('@/service/eamasset-state-model-line/eamasset-state-model-line-service'));
        this.allEntityService.set('woorigin', () => import('@/service/woorigin/woorigin-service'));
        this.allEntityService.set('eamapplytype', () => import('@/service/eamapply-type/eamapply-type-service'));
        this.allEntityService.set('eamproduct', () => import('@/service/eamproduct/eamproduct-service'));
        this.allEntityService.set('eamservicelevel', () => import('@/service/eamservice-level/eamservice-level-service'));
        this.allEntityService.set('eamsparepartspro', () => import('@/service/eamspare-parts-pro/eamspare-parts-pro-service'));
        this.allEntityService.set('eamapplystatemodelline', () => import('@/service/eamapply-state-model-line/eamapply-state-model-line-service'));
        this.allEntityService.set('eamsparepartsgroup', () => import('@/service/eamspare-parts-group/eamspare-parts-group-service'));
        this.allEntityService.set('eamlocationstatemodelline', () => import('@/service/eamlocation-state-model-line/eamlocation-state-model-line-service'));
        this.allEntityService.set('eamassetpartsgroup', () => import('@/service/eamasset-parts-group/eamasset-parts-group-service'));
        this.allEntityService.set('eamasset', () => import('@/service/eamasset/eamasset-service'));
        this.allEntityService.set('eamapplystate', () => import('@/service/eamapply-state/eamapply-state-service'));
        this.allEntityService.set('eamapply', () => import('@/service/eamapply/eamapply-service'));
        this.allEntityService.set('eamwostate', () => import('@/service/eamwostate/eamwostate-service'));
        this.allEntityService.set('eamassetstatemodel', () => import('@/service/eamasset-state-model/eamasset-state-model-service'));
        this.allEntityService.set('eamwotype', () => import('@/service/eamwotype/eamwotype-service'));
    }

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

    /**
     * 获取应用实体数据服务
     *
     * @param {string} name
     * @returns {Promise<any>}
     * @memberof EntityServiceRegister
     */
    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 entityServiceRegister: EntityServiceRegister = new EntityServiceRegister();