import { Injectable } from '@angular/core';
import { HttpRequestService } from '../http-request.service';
import { map, Observable } from 'rxjs';
import { ResponseDataGetStockBarcode, UpdateStockBarcode } from '../../interfaces/inventory-management/barcode-management.interface';
import { ResponseData } from '../resources.service';
import { ResponseDataGetDescriptionSheetStock } from '../../interfaces/inventory-management/description-sheet-stock.interface';
import { RequestFormDocument, ResponseDataGetDocumentAssociation, ResponseDataGetDocumentByStock } from '../../interfaces/inventory-management/document-association.interface';
import { ResponseDataGetDueDateStock, UpdateDueDateStock } from '../../interfaces/inventory-management/due-date-stock.interface';
import { RequestMoveStock, ResponseDataGetExchangeArticles } from '../../interfaces/inventory-management/exchange-articles.interface';
import { ResponseDataGetDetailsLocation, ResponseDataGetLocationByStock, ResponseDataGetLocationStock } from '../../interfaces/inventory-management/location-stock.interface';
import { ResponseDataGetMaxMinStock, UpdateStockMaxMin } from '../../interfaces/inventory-management/max-min-stock.interface';
import { RequestFormSearch, ResponseDataGetInfoByStock, ResponseDataSearch } from '../../interfaces/inventory-management/multi-criteria-search.interface';
import { ResponseDataDetailsNomenclature, ResponseDataGetNomenclature } from '../../interfaces/inventory-management/nomenclature-management.interface';
import { RequestSaveInfo, ResponseDataGetDetailsObjectProperties, ResponseDataGetObjectsProperties } from '../../interfaces/inventory-management/object-properties-artitle.interface';
import { RequestObjectRequestLine, ResponseDataGetReplanishmentQuantities, ResponseDataGetReplenismentSuggestion } from '../../interfaces/inventory-management/replenishment-quantities.interface';
import { GetWarehouse, RegisterToStock, RequestFormArea, RequestFormLevel, RequestFormZone, ResponseDataAreaWarehouse, ResponseDataGetAreaWarehouse, ResponseDataGetLevelAreaWarehouse, ResponseDataGetWarehouse, ResponseDataGetZoneLevelAreaWarehouse, ResponseDataLevelAreaWarehouse, ResponseDataWarehouse, ResponseDataZoneLevelAreaWarehouse } from '../../interfaces/inventory-management/warehouse-management.interface';
import { RequestUserNumberLine } from '../../interfaces/response-data';
import { ResponseDataGetToolsAndSpare } from '../../interfaces/inventory-management/tools-and-spare.interface';
import { ReponseDataGetGetArticlesWithoutMovements, ResponseDataGetClassificate } from '../../interfaces/inventory-management/inventory-management.inerface';

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

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

  public getStockBarcode(user: string, line: number): Observable<ResponseDataGetStockBarcode> {
    return this._httpRequestService.getQuery(`${this._url}/get-stock-barcode/${user}/${line}`).pipe(map((data:any) => data));
  }
  public updateStockBarcode(idStock: string, updateStockBarcode: UpdateStockBarcode): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/update-stock-barcode/${idStock}`, updateStockBarcode).pipe(map((data:any) => data));
  }

  public getDescriptionSheetStock(user: string, line: number): Observable<ResponseDataGetDescriptionSheetStock> {
    return this._httpRequestService.getQuery(`${this._url}/get-description-sheet-stock/${user}/${line}`).pipe(map((data:any) => data));
  }
  public createDescriptionSheetStockXLS(idStock: string, user: string, line: number): Observable<ResponseData> {
    return this._httpRequestService.getQuery(`${this._url}/create-description-sheet-stock-xls/${idStock}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public createDescriptionSheetStockPDF(idStock: string, user: string, line: number): Observable<ResponseData> {
    return this._httpRequestService.getQuery(`${this._url}/create-description-sheet-stock-pdf/${idStock}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getDocumentAssociation(user: string, line: number): Observable<ResponseDataGetDocumentAssociation> {
    return this._httpRequestService.getQuery(`${this._url}/get-document-association/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getDocumentsByStock(idStock: string, user: string, line: number): Observable<ResponseDataGetDocumentByStock> {
    return this._httpRequestService.getQuery(`${this._url}/get-documents-by-stock/${idStock}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public registerDocumentStock(requestFormDocument: RequestFormDocument): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/register-document-stock`, requestFormDocument).pipe(map((data:any) => data));
  }

  public getDueDateStock(user: string, line: number): Observable<ResponseDataGetDueDateStock> {
    return this._httpRequestService.getQuery(`${this._url}/get-due-date-stock/${user}/${line}`).pipe(map((data:any) => data));
  }
  public updateDueDateStock(idStock: string, updateDueDateStock: UpdateDueDateStock): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/update-due-date-stock/${idStock}`, updateDueDateStock).pipe(map((data:any) => data));
  }

  public getCurrentLocationArtitles(user: string, line: number): Observable<ResponseDataGetExchangeArticles> {
    return this._httpRequestService.getQuery(`${this._url}/get-current-location-artitles/${user}/${line}`).pipe(map((data:any) => data));
  }
  public moveToStock(requestData: RequestMoveStock, idStock: string): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/move-to-stock/${idStock}`, requestData).pipe(map((data:any) => data));
  }

  public getLocationStock(user: string, line: number) : Observable<ResponseDataGetLocationStock> {
    return this._httpRequestService.getQuery(`${this._url}/get-location-stock/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getLocationByStock(idStock: string, user: string, line: number) : Observable<ResponseDataGetLocationByStock> {
    return this._httpRequestService.getQuery(`${this._url}/get-location-by-stock/${idStock}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getDetaisLocation(idStock: string, idLocation: string, user: string, line: number) : Observable<ResponseDataGetDetailsLocation> {
    return this._httpRequestService.getQuery(`${this._url}/get-details-location/${idStock}/${idLocation}/${user}/${line}`).pipe(map((data:any) => data));
  }

  public getMaxMinStock(user: string, line: number) : Observable<ResponseDataGetMaxMinStock> {
    return this._httpRequestService.getQuery(`${this._url}/get-max-min-stock/${user}/${line}`).pipe(map((data:any) => data));
  }
  public updateStockMaxMin(idInfo: string, updateStockMaxMin: UpdateStockMaxMin): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/update-stock-max-min/${idInfo}`, updateStockMaxMin).pipe(map((data:any) => data));
  }

  public search(jsonRequest: RequestFormSearch) : Observable<ResponseDataSearch> {
    return this._httpRequestService.postQuery(`${this._url}/search`, jsonRequest).pipe(map((data:any) => data));
  }
  public getInfoByStock(idStock: string, user: string, line: number) : Observable<ResponseDataGetInfoByStock> {
    return this._httpRequestService.getQuery(`${this._url}/get-info-by-stock/${idStock}/${user}/${line}`).pipe(map((data:any) => data));
  }

  public getNomenclatureManagement(user: string, line: number): Observable<ResponseDataGetNomenclature> {
    return this._httpRequestService.getQuery(`${this._url}/get-nomenclature-management/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getDetailsNomenclature(idStock: string, user: string, line: number): Observable<ResponseDataDetailsNomenclature> {
    return this._httpRequestService.getQuery(`${this._url}/get-details-nomenclature/${idStock}/${user}/${line}`).pipe(map((data:any) => data));
  }

  public getObjectProperties(user: string, line: number): Observable<ResponseDataGetObjectsProperties> {
    return this._httpRequestService.getQuery(`${this._url}/get-objects-properties/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getDetailsObjectProperties(idStock: string, user: string, line: number): Observable<ResponseDataGetDetailsObjectProperties> {
    return this._httpRequestService.getQuery(`${this._url}/get-details-object-properties/${idStock}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public saveInfoStock(requestSaveInfo: RequestSaveInfo, idStock: string): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/save-info-stock/${idStock}`, requestSaveInfo).pipe(map((data:any) => data));
  }

  public getReplenishmentQuantitiesService(user: string, line: number): Observable<ResponseDataGetReplanishmentQuantities> {
    return this._httpRequestService.getQuery(`${this._url}/get-replanishment-quantities/${user}/${line}`).pipe(map((data:any) => data));
  }
  public createRequestLine(requestObjectRequestLine: RequestObjectRequestLine): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/create-request-line`, requestObjectRequestLine).pipe(map((data:any) => data));
  }



  public registerArtitleWithoutOrder(objectRequest: any):  Observable<any> {
    return this._httpRequestService.postQuery(`${this._url}/register-artitle-without-order`, objectRequest).pipe(map((data:any) => { data }))
  }
  

  public getWarehouse(user: string, line: number) : Observable<ResponseDataGetWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-warehouse/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getWarehouseById(idWarehouse:string, user: string, line: number) : Observable<ResponseDataWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-warehouse-by-id/${idWarehouse}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getWarehouseActives(user: string, line: number) : Observable<ResponseDataGetWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-warehouse-actives/${user}/${line}`).pipe(map((data:any) => data));
  }
  public createWarehouse( objectRequest: GetWarehouse ) : Observable<ResponseData>  {
    return this._httpRequestService.postQuery(`${this._url}/create-warehouse`, objectRequest).pipe(map((data:any) => data ));
  }
  public updateWarehouse( objectRequest: GetWarehouse, idWarehouse:string ) : Observable<ResponseData>  {
    return this._httpRequestService.postQuery(`${this._url}/update-warehouse/${idWarehouse}`, objectRequest).pipe(map((data:any) => data));
  }
  public deleteWarehouse( objectRequest: RequestUserNumberLine, idWarehouse:string ) : Observable<ResponseData>  {
    return this._httpRequestService.postQuery(`${this._url}/delete-warehouse/${idWarehouse}`, objectRequest).pipe(map((data:any) => data));
  }


  public getAreaByWarehouse(idWarehouse: string, user: string, line: number) : Observable<ResponseDataGetAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-area-by-warehouse/${idWarehouse}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getAreaById(idArea: string, user: string, line: number) : Observable<ResponseDataAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-area-by-id/${idArea}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getAreaByWarehouseActives(idWarehouse: string, user: string, line: number) : Observable<ResponseDataGetAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-area-by-warehouse-actives/${idWarehouse}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public registerArea(objectRequest: RequestFormArea): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/register-area`, objectRequest).pipe(map((data:any) => data));
  }
  public updateArea(objectRequest: RequestFormArea, idArea: string, user: string, line: number): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/update-area/${idArea}`, objectRequest).pipe(map((data:any) => data));
  }
  public deleteArea(objectRequest: RequestUserNumberLine, idArea: string, user: string, line: number): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/delete-area/${idArea}`, objectRequest).pipe(map((data:any) => data));
  }
  
  
  public getLevelByAreaWarehouse(idWarehouse: string, idArea: string, user: string, line: number): Observable<ResponseDataGetLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-level-by-area-warehouse/${idWarehouse}/${idArea}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getLevelById(idLevel: string, user: string, line: number): Observable<ResponseDataLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-level-by-id/${idLevel}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getLevelByAreaWarehouseActives(idWarehouse: string, idArea: string, user: string, line: number): Observable<ResponseDataGetLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-level-by-area-warehouse-actives/${idWarehouse}/${idArea}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public registerLevel(objectRequest: RequestFormLevel): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/register-level`, objectRequest).pipe(map((data:any) => data));
  }
  public updateLevel(objectRequest: RequestFormLevel, idLevel: string): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/update-level/${idLevel}`, objectRequest).pipe(map((data:any) => data));
  }
  public deleteLevel(objectRequest: RequestUserNumberLine, idLevel: string): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/delete-level/${idLevel}`, objectRequest).pipe(map((data:any) => data));
  }



  public getZoneByLevelAreaWarehouse(idWarehouse: string, idArea: string, idLevel: string, user: string, line: number): Observable<ResponseDataGetZoneLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-zone-by-level-area-warehouse/${idWarehouse}/${idArea}/${idLevel}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getZoneById(idLevel: string, user: string, line: number): Observable<ResponseDataZoneLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-zone-by-id/${idLevel}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getZoneByLevelAreaWarehouseActive(idWarehouse: string, idArea: string, idLevel: string, user: string, line: number): Observable<ResponseDataGetZoneLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-zone-by-level-area-warehouse-actives/${idWarehouse}/${idArea}/${idLevel}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public registerZone(objectRequest: RequestFormZone): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/register-zone`, objectRequest).pipe(map((data:any) => data));
  }
  public updateZone(objectRequest: RequestFormZone, idLevel: string): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/update-zone/${idLevel}`, objectRequest).pipe(map((data:any) => data));
  }
  public deleteZone(objectRequest: RequestUserNumberLine, idLevel: string): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/delete-zone/${idLevel}`, objectRequest).pipe(map((data:any) => data));
  }
  
  public registerToStock(objectRequest: RegisterToStock): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/register-to-stock`, objectRequest).pipe(map((data:any) => data));
  }

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


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

  public getArticleClassificateByWarehouse (idWarehouse: string, user: string, line: number) : Observable<ResponseDataGetClassificate> {
    return this._httpRequestService.getQuery(`${this._url}/get-article-classificate-by-warehouse/${idWarehouse}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getValueStockByPeriod (idWarehouse: string, user: string, line: number) {
    return this._httpRequestService.getQuery(`${this._url}/get-value-stock-by-period/${idWarehouse}/${user}/${line}`).pipe(map((data:any) => data));
  }
  public getArticlesWithoutMovements (user: string, line: number) : Observable<ReponseDataGetGetArticlesWithoutMovements> {
    return this._httpRequestService.getQuery(`${this._url}/get-article-without-movements/${user}/${line}`).pipe(map((data:any) => data));
  }
}
