import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {Observable} from "rxjs";
import {StakeholderPublication} from "./irish";
import {properties} from "../../environments/environment";
import {Stakeholder, StakeholderType} from "../openaireLibrary/monitor/entities/stakeholder";
import {CustomOptions} from "../openaireLibrary/services/servicesUtils/customOptions.class";
import {map} from "rxjs/operators";
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";

@Injectable({
  providedIn: 'root'
})
export class IrishMonitorService {


  constructor(private http: HttpClient) {
  }

  public getStakeholdersWithPublications(type: StakeholderType): Observable<StakeholderPublication[]> {
    return this.http.get<StakeholderPublication[]>(properties.monitorServiceAPIURL + '/publications/' + type, CustomOptions.registryOptions()).pipe(map(stakeholders => {
      return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholders));
    }));
  }
}
