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

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

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

  // Obtener familias y subfamilias
  public getFamiliesAndSubfamilies(): Observable<any> {
    return this._httpRequestService.getQuery(`${this._url}/get-families-and-subfamilies`).pipe(map(( data: any ) => data));
  }

  // Obtener artículos
  public getArtitles(): Observable<any> {
    return this._httpRequestService.getQuery(`${ this._url }/get-artitle`).pipe(map(( data:any ) => data))
  }

  // Obtener articulos por identificador
  public getArtitleByProvider(objRequest:ObjectRequest): Observable<any> {
    return this._httpRequestService.postQuery(`${ this._url }/get-artitle-by-provider`, objRequest).pipe(map(( data:any ) => data))
  }

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

  // Obtener todos los articulos
  public getAllArtitle(): Observable<any> {
    return this._httpRequestService.getQuery(`${ this._url }/get-all-artitle`).pipe(map(( data:any ) => data))
  }

  public registerArtitle(objRequest:any): Observable<any> {
    return this._httpRequestService.postQuery(`${ this._url }/register-artitle`, objRequest).pipe(map(( data:any ) => data))
  }

  public updateArtitle(objRequest:any): Observable<any> {
    return this._httpRequestService.postQuery(`${ this._url }/update-artitle`, objRequest).pipe(map(( data:any ) => data))
  }

  public deleteArtitle(objRequest:any): Observable<any> {
    return this._httpRequestService.postQuery(`${ this._url }/delete-artitle`, objRequest).pipe(map(( data:any ) => data))
  }

}
