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