import { Injectable } from '@angular/core';
import { HttpRequestService } from 'src/app/services/resources/http-request.service';
import { Observable, map } from 'rxjs';
import { 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 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));
  }
}
