import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '@msfa-environment';
import { mapServiceApiResponseToService, Service, ServiceApiResponse } from '@msfa-models/service.model';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root',
})
export class ServiceService {
  private _apiBaseUrl = `${environment.api.url}/services`;
  public services$: Observable<Service[]> = this.httpClient
    .get<ServiceApiResponse>(this._apiBaseUrl)
    .pipe(map(response => response.data.map(service => mapServiceApiResponseToService(service))));

  constructor(private httpClient: HttpClient) {}
}
