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

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

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

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

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

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

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

  public getArtitleByInformation(idInformation:string): Observable<any> {
    return this._httpRequestService.getQuery(`${ this._url }/get-artitle-by-information/${idInformation}`).pipe(map(( data:any ) => data))
  }

  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))
  }

  public generateArtitles(formData: FormData){
    return this._httpRequestService.postQuery(`${ this._url }/generate-artitles`, formData).pipe(map(( data:any ) => data))
  }

  public downloadTemplate() {
    return this._httpRequestService.getQuery(`${this._url}/download-template`).pipe(map(( data: any ) => data));
  }

  public getArtitlesByProvider(providerNumber: string) {
    return this._httpRequestService.getQuery(`${this._url}/get-artitles-by-provider/${providerNumber}`).pipe(map((data:any) => data));
  }

  public downloadArtitlesByProvider(objResponse: ObjResponseDownload) {
    return this._httpRequestService.postQuery(`${this._url}/download-artitles-by-provider`, objResponse).pipe(map((data:any) => data));
  }

}
