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

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

  private baseUrl: string = "http://localhost:8080/escalas";
  
  constructor(private httpClient: HttpClient) { }  

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

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

  addEscala(query: any): Observable<Object>{    
    return this.httpClient.post(this.baseUrl+"/agregar",query);
  }

  deleteEscala(id:number):Observable<Object>{
    return this.httpClient.delete(`${this.baseUrl+ "/eliminar"}/${id}`);
  }

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

}
