import { Injectable } from '@angular/core';
import { HttpRequestService } from '../resources/http-request.service';
import { Observable, map } from 'rxjs';
import { GetWarehouse, ResponseDataGetLevelAreaWarehouse, ResponseDataLevelAreaWarehouse, RequestFormArea, RequestFormLevel, ResponseDataAreaWarehouse, ResponseDataGetAreaWarehouse, ResponseDataGetWarehouse, ResponseDataWarehouse, ResponseDataGetZoneLevelAreaWarehouse, ResponseDataZoneLevelAreaWarehouse, RequestFormZone, RegisterToStock } from 'src/app/interfaces/inventory-management/warehouse-management.interface';
import { RequestUserNumberLine, ResponseData } from 'src/app/interfaces/response-data';

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

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

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

  public getWarehouse() : Observable<ResponseDataGetWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-warehouse`).pipe(map((data:any) => data));
  }
  public getWarehouseById(idWarehouse:string) : Observable<ResponseDataWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-warehouse-by-id/${idWarehouse}`).pipe(map((data:any) => data));
  }
  public getWarehouseActives() : Observable<ResponseDataGetWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-warehouse-actives`).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.putQuery(`${this._url}/update-warehouse/${idWarehouse}`, objectRequest).pipe(map((data:any) => data));
  }
  public deleteWarehouse( objectRequest: RequestUserNumberLine, idWarehouse:string ) : Observable<ResponseData>  {
    return this._httpRequestService.putQuery(`${this._url}/delete-warehouse/${idWarehouse}`, objectRequest).pipe(map((data:any) => data));
  }


  public getAreaByWarehouse(idWarehouse: string) : Observable<ResponseDataGetAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-area-by-warehouse/${idWarehouse}`).pipe(map((data:any) => data));
  }
  public getAreaById(idArea: string) : Observable<ResponseDataAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-area-by-id/${idArea}`).pipe(map((data:any) => data));
  }
  public getAreaByWarehouseActives(idWarehouse: string) : Observable<ResponseDataGetAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-area-by-warehouse-actives/${idWarehouse}`).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): Observable<ResponseData> {
    return this._httpRequestService.putQuery(`${this._url}/update-area/${idArea}`, objectRequest).pipe(map((data:any) => data));
  }
  public deleteArea(objectRequest: RequestUserNumberLine, idArea: string): Observable<ResponseData> {
    return this._httpRequestService.putQuery(`${this._url}/delete-area/${idArea}`, objectRequest).pipe(map((data:any) => data));
  }
  
  
  public getLevelByAreaWarehouse(idWarehouse: string, idArea: string): Observable<ResponseDataGetLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-level-by-area-warehouse/${idWarehouse}/${idArea}`).pipe(map((data:any) => data));
  }
  public getLevelById(idLevel: string): Observable<ResponseDataLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-level-by-id/${idLevel}`).pipe(map((data:any) => data));
  }
  public getLevelByAreaWarehouseActives(idWarehouse: string, idArea: string): Observable<ResponseDataGetLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-level-by-area-warehouse-actives/${idWarehouse}/${idArea}`).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.putQuery(`${this._url}/update-level/${idLevel}`, objectRequest).pipe(map((data:any) => data));
  }
  public deleteLevel(objectRequest: RequestUserNumberLine, idLevel: string): Observable<ResponseData> {
    return this._httpRequestService.putQuery(`${this._url}/delete-level/${idLevel}`, objectRequest).pipe(map((data:any) => data));
  }



  public getZoneByLevelAreaWarehouse(idWarehouse: string, idArea: string, idLevel: string): Observable<ResponseDataGetZoneLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-zone-by-level-area-warehouse/${idWarehouse}/${idArea}/${idLevel}`).pipe(map((data:any) => data));
  }
  public getZoneById(idLevel: string): Observable<ResponseDataZoneLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-zone-by-id/${idLevel}`).pipe(map((data:any) => data));
  }
  public getZoneByLevelAreaWarehouseActive(idWarehouse: string, idArea: string, idLevel: string): Observable<ResponseDataGetZoneLevelAreaWarehouse> {
    return this._httpRequestService.getQuery(`${this._url}/get-zone-by-level-area-warehouse-actives/${idWarehouse}/${idArea}/${idLevel}`).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.putQuery(`${this._url}/update-zone/${idLevel}`, objectRequest).pipe(map((data:any) => data));
  }
  public deleteZone(objectRequest: RequestUserNumberLine, idLevel: string): Observable<ResponseData> {
    return this._httpRequestService.putQuery(`${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));
  }

}
