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

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

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

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

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

  public getRequestLine(idRequestLine: string) : Observable<any> {
    return this._httpRequestService.getQuery(`${this._url}/get-request-line/${idRequestLine}`).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) {
    return this._httpRequestService.getQuery(`${this._url}/get-artitles-by-request-line/${requestLine}`).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() : Observable<any> {
    return this._httpRequestService.getQuery(`${this._url}/get-orders`).pipe(map((data:any) => data));
  }

  public getOrderByNumber(numberOrder: string, numberProdiver: string) : Observable<any> {
    return this._httpRequestService.getQuery(`${this._url}/get-order-by-number/${numberOrder}/${numberProdiver}`).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) {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-acquisition-xls/${numeroOrden}`).pipe(map((data:any) => data));
  }
  public generateSheetAcquisitionPDF(numeroOrden:string) {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-acquisition-pdf/${numeroOrden}`).pipe(map((data:any) => data));
  }

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

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

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