import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Reserva } from '../interfaces/reservas.interface';

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

  private baseUrl: string = "http://localhost:8080/itinerarios";

  constructor(private httpClient: HttpClient) { }
  
  addReserva(reserva: {estado: string, pasajero: { id: number }, agente: {id: number} }): Observable<Reserva>{
    console.log(reserva);
    return this.httpClient.post<Reserva>(this.baseUrl+"/agregar",reserva);
  }

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

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

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

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

}
