import {Injectable} from "@angular/core";
import {AppConfigService, ApplicationSettingsProvider} from "@webbpm/base-package";
import {HttpClient} from "@angular/common/http";
import {MfeConfigurationProvider} from "../provider/mfe-configuration.provider";
import {joinPath} from "../../../mfe-app-tools";


@Injectable({providedIn:'root'})
export class MfeAppConfigService extends AppConfigService {

  load(): Promise<any> {
    let http: HttpClient = this['http'];
    let url = joinPath(
        MfeConfigurationProvider.MFE_BASE_URL,
        ApplicationSettingsProvider.RESOURCES_PATH,
        'app-config.json'
    )
    return http
        .get(url)
        .toPromise()
        .then(configData => {
          this['mapParam'] = configData;
        })
        .catch((error: any): any => {
          console.error('Account Applications configuration file "app-config.json" could not be read');
          return Promise.reject(error);
        });
  }
}
