import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Pump } from 'src/app/models/pump';
import { PumpModel } from 'src/app/models/pumpModel';
import { Sensor } from 'src/app/models/sensor';
import { Wharf } from 'src/app/models/Wharf';
import { environment } from 'src/environments/environment';

@Injectable({
  providedIn: 'root'
})
export class WerfFormTwoService {
  url = environment.url;

  constructor(private httpClient: HttpClient) { }

  getIdForWharf() {
    return this.httpClient.get<number>(this.url + '/Wharf/getIdForWharf');
  }

  putPump(pump: Pump, id: number): Observable<Pump> {
    let headers = new HttpHeaders();
    headers = headers.set('Content-Type', 'application/json; charset=utf-8');

    return this.httpClient.put<Pump>(this.url + '/Pump/changePump/' + id, pump, {headers: headers});
  }

  getPumps(): Observable<Pump[]> {
    return this.httpClient.get<Pump[]>(this.url + '/Pump/getPumps');
  }

  getSensors(): Observable<Sensor[]> {
    return this.httpClient.get<Sensor[]>(this.url + '/Sensor/getSensors');
  }

  putSensor(sensor: Sensor, id: number): Observable<Sensor> {
    let headers = new HttpHeaders();
    headers = headers.set('Content-Type', 'application/json; charset=utf-8');

    return this.httpClient.put<Sensor>(this.url + '/Sensor/changeSensor/' + id, sensor, {headers: headers});
  }

  getPumptypes(): Observable<PumpModel[]> {
    return this.httpClient.get<PumpModel[]>(this.url + '/PumpModel/getPumpModels');
  }
}
