import { Injectable } from '@angular/core';
import { HttpRequestService } from '../../resources/http-request.service';
import { Observable, map } from 'rxjs';
import { DeleteProvider, RegisterProvider } from 'src/app/interfaces/acquisition-management/provider/provider.interface';

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

  private _url: string;
  constructor( private _httpRequestService:HttpRequestService ) {
    this._url = 'acquisition-management/provider';
  }

  // Obtener proveedores
  public getAllProvider(): Observable<any> {
    return this._httpRequestService.getQuery(`${this._url}/get-all-provider`).pipe(map(( data: any ) => data));
  }

  public getProviderActives(): Observable<any> {
    return this._httpRequestService.getQuery(`${this._url}/get-provider-actives`).pipe(map(( data: any ) => data));
  }

  public registerForm(response:RegisterProvider): Observable<any> {
    return this._httpRequestService.postQuery(`${this._url}/register-provider`, response).pipe(map((data:any) => data));
  }

  public updateForm(response:RegisterProvider): Observable<any> {
    return this._httpRequestService.postQuery(`${this._url}/update-provider`, response).pipe(map((data:any) => data));
  }

  public deteleProvider(response:DeleteProvider): Observable<any> {
    return this._httpRequestService.postQuery(`${this._url}/delete-provider`, response).pipe(map((data:any) => data));
  }

  public getProviderByArtitle(response:any): Observable<any> {
    return this._httpRequestService.postQuery(`${this._url}/get-provider-by-artitle`, response).pipe(map(( data: any ) => data));
  }
}
