/**
 * 实体权限服务注册中心
 *
 * @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('pcmwzd0001', () => import('@/authservice/pcm-wzd0001/pcm-wzd0001-auth-service'));
        this.allAuthService.set('ormbmkqdz', () => import('@/authservice/orm-bmkqdz/orm-bmkqdz-auth-service'));
        this.allAuthService.set('ormorg', () => import('@/authservice/orm-org/orm-org-auth-service'));
        this.allAuthService.set('vacleavetips', () => import('@/authservice/vac-leave-tips/vac-leave-tips-auth-service'));
        this.allAuthService.set('attendencetype', () => import('@/authservice/att-endence-type/att-endence-type-auth-service'));
        this.allAuthService.set('vacholiday', () => import('@/authservice/vac-holiday/vac-holiday-auth-service'));
        this.allAuthService.set('attendancemreportmx', () => import('@/authservice/att-endance-mreportmx/att-endance-mreportmx-auth-service'));
        this.allAuthService.set('vacsynjcx', () => import('@/authservice/vac-synjcx/vac-synjcx-auth-service'));
        this.allAuthService.set('vacleacetype', () => import('@/authservice/vac-leace-type/vac-leace-type-auth-service'));
        this.allAuthService.set('personstatemgr', () => import('@/authservice/person-state-mgr/person-state-mgr-auth-service'));
        this.allAuthService.set('attensummary', () => import('@/authservice/att-ensummary/att-ensummary-auth-service'));
        this.allAuthService.set('vacleavemanage', () => import('@/authservice/vac-leave-manage/vac-leave-manage-auth-service'));
        this.allAuthService.set('attendenceormorgscetor', () => import('@/authservice/att-endence-ormorgscetor/att-endence-ormorgscetor-auth-service'));
        this.allAuthService.set('attendencesetup', () => import('@/authservice/att-endence-setup/att-endence-setup-auth-service'));
        this.allAuthService.set('pimperson', () => import('@/authservice/pim-person/pim-person-auth-service'));
        this.allAuthService.set('vacleavedetail', () => import('@/authservice/vac-leave-detail/vac-leave-detail-auth-service'));
        this.allAuthService.set('attendancerecord', () => import('@/authservice/att-endance-record/att-endance-record-auth-service'));
        this.allAuthService.set('vacholidayrules', () => import('@/authservice/vac-holiday-rules/vac-holiday-rules-auth-service'));
        this.allAuthService.set('ormorgsector', () => import('@/authservice/orm-orgsector/orm-orgsector-auth-service'));
        this.allAuthService.set('attendancemreport', () => import('@/authservice/att-endance-mreport/att-endance-mreport-auth-service'));
        this.allAuthService.set('attendancesettings', () => import('@/authservice/att-endance-settings/att-endance-settings-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();