import { Injectable } from '@angular/core';
import { ConfigService } from '../../config/config.service';
import { FleioApiService } from '../fleio-api.service';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { IBaseFleioObjectModel } from '../base-model/base-fleio-object.model';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class SingleSignOnSettingsApiService extends FleioApiService<IBaseFleioObjectModel> {
  // noinspection JSUnusedGlobalSymbols
  constructor(protected httpClient: HttpClient, protected config: ConfigService) {
    super();
    this.setEndpoint(config.getPanelApiUrl('settings/single-sign-on-settings'));
  }

  getSaml2Metadata(): Observable<string> {
    return this.getAction('get-saml2-metadata').pipe(map(response => response.metadata));
  }

  regenerateCertificate(certificateData: any): Observable<any> {
    return this.postAction('regenerate-saml2-certificate', certificateData);
  }

  uploadCertificate(certificateData: any): Observable<any> {
    return this.postAction('upload-saml2-certificate', certificateData);
  }
}
