import { Injectable } from '@angular/core';
import { DeltagareAvrop } from '@msfa-models/avrop.model';
import { InformativRapport, mapResponseToInformativRapport } from '@msfa-models/informativ-rapport.model';
import { DeltagareApiService } from '@msfa-services/api/deltagare.api.service';
import { HandlingarApiService } from '@msfa-services/api/handlingar.api.service';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable()
export class InformativRapportViewService {
  constructor(private handlingarApiService: HandlingarApiService, private deltagareApiService: DeltagareApiService) {}

  public fetchAvropInformation$(genomforandeReferens: number): Observable<DeltagareAvrop> {
    return this.deltagareApiService.fetchAvropInformation$(genomforandeReferens);
  }

  public fetchInformativRapport$(handlingId: string): Observable<InformativRapport> {
    return this.handlingarApiService
      .fetchInformativRapport$(handlingId)
      .pipe(map(({ data }) => mapResponseToInformativRapport(data)));
  }
}
