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

}
