/**
 * 实体权限服务注册中心
 *
 * @export
 * @class AuthServiceRegister
 */
export class AuthServiceRegister {

    /**
     * 所有实体权限服务Map
     *
     * @protected
     * @type {*}
     * @memberof AuthServiceRegister
     */
    protected allAuthService: Map<string, () => Promise<any>> = new Map();

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

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

    /**
     * 初始化
     *
     * @protected
     * @memberof AuthServiceRegister
     */
    protected init(): void {
                this.allAuthService.set('pcmworkresume', () => import('@/authservice/pcm-work-resume/pcm-work-resume-auth-service'));
        this.allAuthService.set('pcmprofileapproval', () => import('@/authservice/pcm-profile-approval/pcm-profile-approval-auth-service'));
        this.allAuthService.set('pcmgxml', () => import('@/authservice/pcm-gxml/pcm-gxml-auth-service'));
        this.allAuthService.set('ormorg', () => import('@/authservice/orm-org/orm-org-auth-service'));
        this.allAuthService.set('pcmpracticeexperience', () => import('@/authservice/pcm-practice-experience/pcm-practice-experience-auth-service'));
        this.allAuthService.set('ormduty', () => import('@/authservice/orm-duty/orm-duty-auth-service'));
        this.allAuthService.set('pimcity', () => import('@/authservice/pim-city/pim-city-auth-service'));
        this.allAuthService.set('pcmprofileinitnumber', () => import('@/authservice/pcm-profile-init-number/pcm-profile-init-number-auth-service'));
        this.allAuthService.set('pimstafftype', () => import('@/authservice/pim-stafftype/pim-stafftype-auth-service'));
        this.allAuthService.set('pcmprofileszyjtj', () => import('@/authservice/pcm-profile-szyjtj/pcm-profile-szyjtj-auth-service'));
        this.allAuthService.set('pcmxkml', () => import('@/authservice/pcm-xkml/pcm-xkml-auth-service'));
        this.allAuthService.set('pcmprofileyjtjtemp', () => import('@/authservice/pcm-profile-yjtj-temp/pcm-profile-yjtj-temp-auth-service'));
        this.allAuthService.set('pcmprofilespyy', () => import('@/authservice/pcm-profile-spyy/pcm-profile-spyy-auth-service'));
        this.allAuthService.set('ormqygl', () => import('@/authservice/orm-qygl/orm-qygl-auth-service'));
        this.allAuthService.set('pcmprofilefj', () => import('@/authservice/pcm-profile-fj/pcm-profile-fj-auth-service'));
        this.allAuthService.set('pcmzpmeglmx', () => import('@/authservice/pcm-zpmeglmx/pcm-zpmeglmx-auth-service'));
        this.allAuthService.set('codeitem', () => import('@/authservice/code-item/code-item-auth-service'));
        this.allAuthService.set('pcmprofilenumbeprefix', () => import('@/authservice/pcm-profile-num-beprefix/pcm-profile-num-beprefix-auth-service'));
        this.allAuthService.set('pcmcertofreg', () => import('@/authservice/pcm-certofreg/pcm-certofreg-auth-service'));
        this.allAuthService.set('pcmtdzwxx', () => import('@/authservice/pcm-tdzwxx/pcm-tdzwxx-auth-service'));
        this.allAuthService.set('codelist1', () => import('@/authservice/code-list1/code-list1-auth-service'));
        this.allAuthService.set('ormorgsector', () => import('@/authservice/orm-orgsector/orm-orgsector-auth-service'));
        this.allAuthService.set('pcmschooloffice', () => import('@/authservice/pcm-school-office/pcm-school-office-auth-service'));
        this.allAuthService.set('pcmtestresult', () => import('@/authservice/pcm-test-result/pcm-test-result-auth-service'));
        this.allAuthService.set('pcmzpmegl', () => import('@/authservice/pcm-zpmegl/pcm-zpmegl-auth-service'));
        this.allAuthService.set('pcmprofile', () => import('@/authservice/pcm-profile/pcm-profile-auth-service'));
        this.allAuthService.set('pcmawardswons', () => import('@/authservice/pcm-awards-wons/pcm-awards-wons-auth-service'));
        this.allAuthService.set('pcmeducationexperience', () => import('@/authservice/pcm-education-experience/pcm-education-experience-auth-service'));
        this.allAuthService.set('ormpost', () => import('@/authservice/orm-post/orm-post-auth-service'));
        this.allAuthService.set('pimqualmajor', () => import('@/authservice/pim-qual-major/pim-qual-major-auth-service'));
        this.allAuthService.set('pcmwzd0001', () => import('@/authservice/pcm-wzd0001/pcm-wzd0001-auth-service'));
        this.allAuthService.set('pimperson', () => import('@/authservice/pim-person/pim-person-auth-service'));
        this.allAuthService.set('pcmgxxktemp', () => import('@/authservice/pcmgxxk-temp/pcmgxxk-temp-auth-service'));
    }

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

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

}
export const authServiceRegister: AuthServiceRegister = new AuthServiceRegister();