import { Injectable } from '@angular/core';
import { DeltagareAvrop } from '@msfa-models/avrop.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';
import { mapResponseToSignal, Signal } from '@msfa-models/signal.model';

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

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

  public fetchSignal$(handlingId: string): Observable<Signal> {
    return this.handlingarApiService.fetchSignal$(handlingId).pipe(map(({ data }) => mapResponseToSignal(data)));
  }
}
