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

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

  constructor(private httpClient: HttpClient) { }

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

  postWharf(wharf: Wharf): Observable<Wharf> {
    let headers = new HttpHeaders();
    headers = headers.set('Content-Type', 'application/json; charset=utf-8');

    return this.httpClient.post<Wharf>(this.url + '/Wharf/addWharf', wharf, {headers: headers});
  }

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

    return this.httpClient.put<Wharf>(this.url + '/Wharf/changeWharf/' + id, wharf, {headers: headers});
  }

  getWharfById(id: number): Observable<Wharf> {
    return this.httpClient.get<Wharf>(this.url + '/Wharf/' + id);
  }

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

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

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