import { Injectable } from '@angular/core';
import { HttpRequestService } from '../http-request.service';
import { map, Observable } from 'rxjs';
import { FormRequestArticle, RequestFormUnits, ResponseDataGetUnits, ResponseDataUnit } from '../../interfaces/acquisition-management/artitle.interface';
import { RequestUserNumberLine, ResponseData } from '../../interfaces/response-data';
import { FormReportProblem } from '../../interfaces/acquisition-management/issue-tracking.interface';
import { ObjectDeleteArtitleByRequestLine, ObjectGetRequest, ObjectRequestLine } from '../../interfaces/acquisition-management/order.interface';
import { DeleteRequestDocument, RegisterFormDocument } from '../../interfaces/acquisition-management/document-order.interface';

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

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

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

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

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

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

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

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

  public registerArticle (formRequest: FormRequestArticle): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${ this._url }/register-article`, formRequest).pipe(map(( data:any ) => data))
  }

  public updateArticle (idArticle: string, formRequest: FormRequestArticle): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${ this._url }/update-article/${idArticle}`, formRequest).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(user: string, line:number) {
    return this._httpRequestService.getQuery(`${this._url}/download-template/${user}/${line}`).pipe(map(( data: any ) => data));
  }

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

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

  public reportProblem(objRequestLine:FormReportProblem) {
    return this._httpRequestService.postQuery(`${ this._url }/report-problem-order`, objRequestLine).pipe(map((data:any) => data));
  }

  public createRequestLine(objRequestLine:ObjectRequestLine) {
    return this._httpRequestService.postQuery(`${ this._url }/create-request-line`, objRequestLine).pipe(map( (data:any) => data ));
  }

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

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

  public cancelRequestLine(objectGetRequest: ObjectGetRequest) : Observable<any> {
    return this._httpRequestService.postQuery(`${this._url}/cancel-request-line`, objectGetRequest).pipe(map((data:any) => data));
  }

  public getArtitlesByRequestLine(requestLine: string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${this._url}/get-artitles-by-request-line/${requestLine}/${user}/${line}`).pipe(map((data:any) => data));
  }

  public deleteArtitleByRequestLine(objectDeleteArtitle: ObjectDeleteArtitleByRequestLine) {
    return this._httpRequestService.postQuery(`${this._url}/delete-artitle-by-request-line`, objectDeleteArtitle).pipe(map((data:any) => data));
  }

  public generateOrders(objectRequest: any) : Observable<any> {
    return this._httpRequestService.postQuery(`${this._url}/register-order`, objectRequest).pipe(map((data:any) => data));
  }

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

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

  public updateStateHistory(objectRequest: any) {
    return this._httpRequestService.postQuery(`${this._url}/update-state-order`, objectRequest).pipe(map((data:any) => data));
  }

  public reorderArtitles(objectRequest: any) {
    return this._httpRequestService.postQuery(`${this._url}/reorder-artitles`, objectRequest).pipe(map((data:any) => data));
  }

  public generateSheetAcquisitionXLS(numeroOrden:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-acquisition-xls/${numeroOrden}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public generateSheetAcquisitionPDF(numeroOrden:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-acquisition-pdf/${numeroOrden}/${user}/${line}`).pipe(map((data:any) => data));
  }

  public generateSheetDivisaXLS(numeroOrden:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-divisa-xls/${numeroOrden}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public generateSheetDivisaPDF(numeroOrden:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-divisa-pdf/${numeroOrden}/${user}/${line}`).pipe(map((data:any) => data));
  }

  public generateSheetInvoiceXLS(numeroOrden:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-invoice-xls/${numeroOrden}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public generateSheetInvoicePDF(numeroOrden:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-invoice-pdf/${numeroOrden}/${user}/${line}`).pipe(map((data:any) => data));
  }

  public getLastSateOrder(numeroOrden:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${this._url}/get-last-state-order/${numeroOrden}/${user}/${line}`).pipe(map((data:any) => data));
  }

  public getOrderReception(user: string, line:number) {
    return this._httpRequestService.getQuery(`${ this._url }/get-delay-analysis/${user}/${line}`).pipe(map((data:any) => data));
  }

  public getDocumentsOrder(user: string, line:number) {
    return this._httpRequestService.getQuery(`${ this._url }/get-documents-order/${user}/${line}`).pipe(map( (data:any) => data ));
  }

  public getDocumentsByRequestLine(requestLine:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${ this._url }/get-documents-by-request-line/${requestLine}/${user}/${line}`).pipe(map( (data:any) => data ));
  }

  public registerDocumentOrder(requestDocument: RegisterFormDocument) {
    return this._httpRequestService.postQuery(`${ this._url }/register-document-order`, requestDocument).pipe(map( (data:any) => data ));
  }

  public updateDocumentOrder(requestDocument: RegisterFormDocument) {
    return this._httpRequestService.postQuery(`${ this._url }/update-document-order`, requestDocument).pipe(map( (data:any) => data ));
  }

  public deleteDocumentOrder(deleteRequestDocument: DeleteRequestDocument) {
    return this._httpRequestService.postQuery(`${ this._url }/delete-document-order`, deleteRequestDocument).pipe(map( (data:any) => data ));
  }

  public getManagementUnit(user: string, line: number): Observable<ResponseDataGetUnits> {
    return this._httpRequestService.getQuery(`${this._url}/get-management-unit/${user}/${line}`).pipe(map( (data:any) => data ));
  }
  public createUnit(requestData: RequestFormUnits): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/create-unit`, requestData).pipe(map((data:any) => data));
  }
  public updateUnit(requestData: RequestFormUnits, idUnit: string): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/update-unit/${idUnit}`, requestData).pipe(map((data:any) => data));
  }
  public getUnitById (idUnit: string, user: string, line: number): Observable<ResponseDataUnit> {
    return this._httpRequestService.getQuery(`${this._url}/get-unit-by-id/${idUnit}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public deleteUnit (requestForm: RequestUserNumberLine, idUnit: string): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/delete-unit-by-id/${idUnit}`, requestForm).pipe(map((data:any) => data));
  }
}
