import { Injectable } from '@angular/core';
import { Observable, of, throwError } from 'rxjs';
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { catchError, tap, map } from 'rxjs/operators';

const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable({
  providedIn: 'root'
})
export class TableMonitoringService {

  apiBaseURL = 'assets/data';
  loadMonitoringRoomDataURL = null;
  loadMonitoringBuildingDataURL = null;
   constructor(private http: HttpClient) {
    this.loadMonitoringRoomDataURL = `${this.apiBaseURL}/hemat/monitoring.json`;
    this.loadMonitoringBuildingDataURL = `${this.apiBaseURL}/hemat/building.json`;
  }
  private handleError(error: HttpErrorResponse) {
    if (error.error instanceof ErrorEvent) {
      // Error
      console.error('error:', error.error.message);
    } else {
      // Error
      console.error(
        `Api server returned ${error.status}, ` +
        `error body: ${error.error}`);
    }
    // throwError is observable
    return throwError('Error has happened');
  }

  private extractData(res: Response) {
    const body = res;
    return body || {};
  }


  getMonitoringRoomData(): Observable<any> {
    return this.http.get(this.loadMonitoringRoomDataURL, httpOptions);
  }

  getMonitoringBuildingData(): Observable<any> {
    return this.http.get(this.loadMonitoringBuildingDataURL, httpOptions);
  }

  
}

