import AmbientConfig from "../config/AmbientConfig";
import { SettingsConfigType, UserConfigMap } from "../config/SettingsConfig";
import { BaseAPI } from "./BaseAPI";

export class AmbientPACEAPI extends BaseAPI {
  private _baseUrl: string;
  constructor(private _config: AmbientConfig) {
    super();
    this._baseUrl = `https://${_config.server}/pace/v1/sdk`;
  }

  private getURL(path: string): string {
    return `${this._baseUrl}${path}`;
  }

  async getNoteParams(): Promise<any> {
    const url = this.getURL("/noteparams");
    const requestData = {
      SubscriptionCode: this._config.subscriptionCode,
      AccessKey: this._config.accessKey,
      UserTag: this._config.userTag,
    };
    return await this.makePostRequest(url, requestData);
  }

  async getSettingsConfigMaster(
    _configTypeId: SettingsConfigType
  ): Promise<any> {
    const url = this.getURL("/configmaster");
    const requestData = {
      SubscriptionCode: this._config.subscriptionCode,
      AccessKey: this._config.accessKey,
      UserTag: this._config.userTag,
      ConfigTypeId: _configTypeId as number,
    };
    return await this.makePostRequest(url, requestData);
  }

  async getUserConfigSettings(_configTypeId: SettingsConfigType): Promise<any> {
    const url = this.getURL("/userconfigmapping");
    const requestData = {
      SubscriptionCode: this._config.subscriptionCode,
      AccessKey: this._config.accessKey,
      UserTag: this._config.userTag,
      ConfigTypeId: _configTypeId as number,
    };
    return await this.makePostRequest(url, requestData);
  }

  async updateUserConfig(_updateSettingRequest: UserConfigMap[]): Promise<any> {
    const url = this.getURL("/userconfigmapping");
    const requestData = {
      SubscriptionCode: this._config.subscriptionCode,
      AccessKey: this._config.accessKey,
      UserTag: this._config.userTag,
      UserConfigMapping: _updateSettingRequest,
    };
    return await this.makePatchRequest(url, requestData);
  }

  async getUserPreferences(): Promise<any> {
    const url = this.getURL('/getuserpreferences');
    const requestData = {
      SubscriptionCode: this._config.subscriptionCode,
      AccessKey: this._config.accessKey,
      UserTag: this._config.userTag,
    };
    return await this.makePostRequest(url, requestData);
  }

  async updateUserPreference(_automaticallyGenerateTranscript: boolean, _preferredTranscriptionLanguage: string, _highlightMedicalTerms: boolean, _displayPatientContext: boolean): Promise<any> {
    const url = this.getURL('/postuserpreferences');
    const requestData = {
      SubscriptionCode: this._config.subscriptionCode,
      AccessKey: this._config.accessKey,
      UserTag: this._config.userTag,
      UserPreferences: {
        AutomaticallyGenerateTranscript: _automaticallyGenerateTranscript,
        PreferredTranscriptionLanguage: _preferredTranscriptionLanguage,
        HighlightMedicalTerms: _highlightMedicalTerms,
        DisplayPatientContext: _displayPatientContext
      }
    };
    return await this.makePostRequest(url, requestData);
  }
}
