import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { WarehouseVO, WarehouseForm, WarehouseId, WarehouseIds, WarehouseQuery } from '@/api/wcs/warehouse/types';

/**
 * 查询仓库信息列表
 * @param query
 * @returns {*}
 */

export const listWarehouse = (query?: WarehouseQuery): AxiosPromise<WarehouseVO[]> => {
  return request({
    url: '/wcs/warehouse/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询仓库信息详细
 * @param warehouseId
 */
export const getWarehouse = (warehouseId: WarehouseId): AxiosPromise<WarehouseVO> => {
  return request({
    url: '/wcs/warehouse/' + warehouseId,
    method: 'get'
  });
};

/**
 * 批量查询仓库信息详细
 * @param ids
 */
export const getWarehouseByIds = (ids: WarehouseIds): AxiosPromise<WarehouseVO[]> => {
  return request({
    url: '/wcs/warehouse/listByIds',
    method: 'post',
    data: ids
  });
};

/**
 * 统计仓库信息数量
 * @param query
 */
export const countWarehouse = (query?: WarehouseQuery): AxiosPromise<number> => {
  return request({
    url: '/wcs/warehouse/count',
    method: 'get',
    params: query
  });
};

/**
 * 判断是否存在符合条件的仓库信息
 * @param query
 */
export const existsWarehouse = (query?: WarehouseQuery): AxiosPromise<boolean> => {
  return request({
    url: '/wcs/warehouse/exists',
    method: 'get',
    params: query
  });
};

/**
 * 新增仓库信息
 * @param data
 */
export const addWarehouse = (data: WarehouseForm) => {
  return request({
    url: '/wcs/warehouse',
    method: 'post',
    data: data
  });
};

/**
 * 修改仓库信息
 * @param data
 */
export const updateWarehouse = (data: WarehouseForm) => {
  return request({
    url: '/wcs/warehouse',
    method: 'put',
    data: data
  });
};

/**
 * 删除仓库信息
 * @param warehouseId
 */
export const delWarehouse = (warehouseId: WarehouseId | WarehouseIds) => {
  return request({
    url: '/wcs/warehouse/' + warehouseId,
    method: 'delete'
  });
};
