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

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

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

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

  public getDispatchActive(user: string, line:number) : Observable<any> {
    return this._httpRequestService.getQuery(`${this._url}/get-dispatch-active/${user}/${line}`).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, user: string, line:number) {
    return this._httpRequestService.getQuery(`${this._url}/get-dispatch-by-id/${idDispatch}/${user}/${line}`).pipe(map((data:any) => data));
  }


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

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

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

  public resolutionIssueTracking(objRequestLine:FormResolutionIssueTracking) {
    return this._httpRequestService.postQuery(`${ this._url }/resolution-issue-tracking`, objRequestLine).pipe(map((data:any) => data));
  }

  public getOrderReception(user: string, line:number) {
    return this._httpRequestService.getQuery(`${ this._url }/get-order-reception/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getListArtitleReception(orderNumber:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${ this._url }/get-list-artitle-reception/${orderNumber}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getInformartionArtitleToEquipment(orderNumber:string, information:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${ this._url }/get-information-artitle-equipment/${orderNumber}/${information}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public generateSheetDeliveryListXLS(orderNumber:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${ this._url }/generate-sheet-delivery-list-xls/${orderNumber}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public generateSheetDeliveryListPDF(orderNumber:string, user: string, line:number) {
    return this._httpRequestService.getQuery(`${ this._url }/generate-sheet-delivery-list-pdf/${orderNumber}/${user}/${line}`).pipe(map((data:any) => data));
  }
}
