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

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

  private baseUrl: string = "http://localhost:9077/AVB/service/pasajero";
  
  private baseUrlS: string = "http://localhost:9077/AVB/service/vuelo";

  private baseUrl2: string = "http://localhost:9077/AVB/service/escala";

  private baseUrl4: string = "http://localhost:9077/AVB/service/itinerarios";


  constructor(private httpClient: HttpClient) { }
  
  getPasajeros(): Observable<any[]>{
    return this.httpClient.get<any[]>(`${ this.baseUrl }/all`);
  }

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


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

  getEscalasByVueloId(id: number): Observable<any[]>{
    return this.httpClient.get<any>(`${ this.baseUrl2 }/listar/${ id }/vuelos`);
  }

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

  addEscalaAReserva(idReserva: number,idEscala:number): Observable<Object>{
    return this.httpClient.post(`${ this.baseUrl2 }/reserva/${idReserva}`,{id: idEscala});
  }

}
