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

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

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

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

  public getDispatchActive() : Observable<any> {
    return this._httpRequestService.getQuery(`${this._url}/get-dispatch-active`).pipe(map((data:any) => data));
  }

  public registerDispatch(objRequest: DispatchRequest) {
    return this._httpRequestService.postQuery(`${this._url}/register-dispatch`, objRequest).pipe(map((data:any) => data));
  }

  public updateDispatch(objRequest: DispatchRequest) {
    return this._httpRequestService.postQuery(`${this._url}/update-dispatch`, objRequest).pipe(map((data:any) => data));
  }

  public deleteDispatch(objRequest: RequestDeleteDispatch) {
    return this._httpRequestService.postQuery(`${this._url}/delete-dispatch`, objRequest).pipe(map((data:any) => data));
  }
  
  public getDispatchById(idDispatch: string) {
    return this._httpRequestService.getQuery(`${this._url}/get-dispatch-by-id/${idDispatch}`).pipe(map((data:any) => data));
  }
}
