/**
 * 实体数据服务注册中心
 *
 * @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('hroperationunit', () => import('@/service/hroperation-unit/hroperation-unit-service'));
        this.allEntityService.set('hrfamily', () => import('@/service/hrfamily/hrfamily-service'));
        this.allEntityService.set('hrreward', () => import('@/service/hrreward/hrreward-service'));
        this.allEntityService.set('hromhierarchypurposeref', () => import('@/service/hromhierarchy-purpose-ref/hromhierarchy-purpose-ref-service'));
        this.allEntityService.set('hromhierarchycat', () => import('@/service/hromhierarchy-cat/hromhierarchy-cat-service'));
        this.allEntityService.set('hrcertificate', () => import('@/service/hrcertificate/hrcertificate-service'));
        this.allEntityService.set('hrorgcontact', () => import('@/service/hrorg-contact/hrorg-contact-service'));
        this.allEntityService.set('hrempstate', () => import('@/service/hremp-state/hremp-state-service'));
        this.allEntityService.set('hrtransferapply', () => import('@/service/hrtransfer-apply/hrtransfer-apply-service'));
        this.allEntityService.set('hrtechnicaltitle', () => import('@/service/hrtechnical-title/hrtechnical-title-service'));
        this.allEntityService.set('hremployee', () => import('@/service/hremployee/hremployee-service'));
        this.allEntityService.set('hrlegal', () => import('@/service/hrlegal/hrlegal-service'));
        this.allEntityService.set('hrdutyedu', () => import('@/service/hrduty-edu/hrduty-edu-service'));
        this.allEntityService.set('hrlanguageability', () => import('@/service/hrlanguage-ability/hrlanguage-ability-service'));
        this.allEntityService.set('hromhierarchypurpose', () => import('@/service/hromhierarchypurpose/hromhierarchypurpose-service'));
        this.allEntityService.set('hromhierarchy', () => import('@/service/hromhierarchy/hromhierarchy-service'));
        this.allEntityService.set('hrworkrecord', () => import('@/service/hrwork-record/hrwork-record-service'));
        this.allEntityService.set('hrdistribution', () => import('@/service/hrdistribution/hrdistribution-service'));
        this.allEntityService.set('hrorgaddress', () => import('@/service/hrorg-address/hrorg-address-service'));
        this.allEntityService.set('hrpost', () => import('@/service/hrpost/hrpost-service'));
        this.allEntityService.set('hrcontract', () => import('@/service/hrcontract/hrcontract-service'));
        this.allEntityService.set('hrpatent', () => import('@/service/hrpatent/hrpatent-service'));
        this.allEntityService.set('hrorganization', () => import('@/service/hrorganization/hrorganization-service'));
        this.allEntityService.set('hrdutyskill', () => import('@/service/hrduty-skill/hrduty-skill-service'));
        this.allEntityService.set('hrdutycert', () => import('@/service/hrduty-cert/hrduty-cert-service'));
        this.allEntityService.set('hreducation', () => import('@/service/hreducation/hreducation-service'));
        this.allEntityService.set('hrduty', () => import('@/service/hrduty/hrduty-service'));
        this.allEntityService.set('hrresearch', () => import('@/service/hrresearch/hrresearch-service'));
        this.allEntityService.set('hrpostrel', () => import('@/service/hrpost-rel/hrpost-rel-service'));
        this.allEntityService.set('hrtrainingrecord', () => import('@/service/hrtraining-record/hrtraining-record-service'));
        this.allEntityService.set('hrpaper', () => import('@/service/hrpaper/hrpaper-service'));
        this.allEntityService.set('hrarchives', () => import('@/service/hrarchives/hrarchives-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();