import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class ReservationsService {

  private urlPassenger: string = "http://localhost:9077/AVB/service/passenger";
  private urlFlight: string = "http://localhost:9077/AVB/service/flight";
  private urlLeg: string = "http://localhost:9077/AVB/service/leg";
  private urlItinerary: string = "http://localhost:9077/AVB/service/itinerarys";

  constructor(private httpClient: HttpClient) { }

  getPassengers(): Observable<any[]> {
    return this.httpClient.get<any[]>(`${this.urlPassenger}/all`);
  }

  getPassenger(id: number): Observable<any> {
    return this.httpClient.get<any>(`${this.urlPassenger}/${id}`);
  }

  getFlights(): Observable<any[]> {
    return this.httpClient.get<any[]>(`${this.urlFlight}/all`);
  }

  getLegsByFlightId(id: number): Observable<any[]> {
    return this.httpClient.get<any>(`${this.urlLeg}/list/${id}/flights`);
  }

  addItinerary(query: any): Observable<any> {
    return this.httpClient.post<any>(this.urlItinerary + "/", query);
  }

  addLegToReservation(idReservation: number, idLeg: number): Observable<Object> {
    return this.httpClient.post(`${this.urlLeg}/reservation/${idReservation}`, {id: idLeg});
  }
}
