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

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

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

  public getAllProvider(user: string, line: number): Observable<ResponseDataProvider> {
    return this._httpRequestService.getQuery(`${this._url}/get-all-provider/${user}/${line}`).pipe(map(( data: any ) => data));
  }

  public getProviderActives(user: string, line: number): Observable<ResponseDataGetProvidersActives> {
    return this._httpRequestService.getQuery(`${this._url}/get-provider-actives/${user}/${line}`).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));
  }

  public getProviderByNumber(numberProvider:string, user: string, line: number): Observable<ResponseDataGetProvidersById> {
    return this._httpRequestService.getQuery(`${this._url}/get-provider-by-number/${numberProvider}/${user}/${line}`).pipe(map(( data: any ) => data));
  }

  public generateSheetProviderXLS(numberProvider:string, typeUser: string, user: string, line: number): Observable<any> {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-provider-xls/${numberProvider}/${typeUser}/${user}/${line}`).pipe(map(( data: any ) => data));
  }
  public generateSheetProviderPDF(numberProvider:string, typeUser: string, user: string, line: number): Observable<any> {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-provider-pdf/${numberProvider}/${typeUser}/${user}/${line}`).pipe(map(( data: any ) => data));
  }
}
