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

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

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

  constructor(private httpClient: HttpClient) { }
  
  getAgentes(): Observable<Agente[]>{
    return this.httpClient.get<Agente[]>(`${ this.baseUrl }/listar`);
  }

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

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

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

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