import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { VueloPost } from '../interfaces/vuelos2.interface';
import { Vuelo } from '../interfaces/vuelos.interface';

@Injectable({
  providedIn: 'root'
})
export class VuelosService {
  private baseUrl: string = "http://localhost:8080/vuelos";

  constructor(private httpClient: HttpClient) { }  

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

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

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

  updateVuelo(id:number,query:any):Observable<Object>{
    return this.httpClient.put(`${this.baseUrl+ "/actualizar"}/${id}`,query);
  }

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

