import { Injectable, Injector } from '@angular/core';
import { cacheConf } from '@conf/cache.conf';
import { sysConf } from '@conf/sys.conf';
import { BaseService } from '../core/base.service';
import { EACacheService } from './../core/cache.service';

@Injectable({
  providedIn: 'root'
})
export class EAEnvironmentService extends BaseService {
  constructor(public injector: Injector, private eaCacheSrv: EACacheService) {
    super(injector);
  }

  /**
   * 环境信息
   */
  public get env(): { appId: string; tenantId: string; enterpriseId: string } {
    const cacheEnv: any = this.eaCacheSrv.get(cacheConf.env);
    // 附加环境变量
    const env: { appId: string; tenantId: string; enterpriseId: string } = {
      appId: cacheEnv?.appId || sysConf.appId,
      tenantId: cacheEnv?.tenantId || sysConf.tenantId,
      enterpriseId: cacheEnv?.enterpriseId || sysConf.enterpriseId
    };
    return env;
  }
}
