import {
  AddStorageParams,
  BaseListResult,
  BaseResult,
  EditStorageParams,
  GetStorageListParams,
  StorageListData,
} from '@models';
import {request} from './request';

const BASE_URL = '/storage';

/** 获取库位列表 */
export function getStorageList(data: GetStorageListParams): BaseListResult<StorageListData> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getStorage`,
    data,
  });
}

/** 获取某个库位详情 */
export function getStorageInfo(id: string): BaseListResult<StorageListData> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getStorage`,
    data: {
      id,
      limit: '1',
      page: '1',
    },
  });
}
/** 新增库位 */
export function addStorage(data: AddStorageParams): BaseResult {
  return request({
    method: 'POST',
    url: `${BASE_URL}/addStorage`,
    data,
  });
}

/** 修改库位 */
export function editStorage(data: EditStorageParams): BaseResult {
  return request({
    method: 'PUT',
    url: `${BASE_URL}/updateStorage`,
    data,
  });
}

/** 删除库位 */
export function deleteStorage(id: string): BaseResult {
  return request({
    method: 'DELETE',
    url: `${BASE_URL}/delStorage`,
    data: {id},
  });
}

/** 导出库位 */
export function exportStorage(data: GetStorageListParams): any {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/export`,
    skipError: true,
  });
}

/** 获取所有库位 */
export function getAllStorage(): BaseResult<StorageListData[]> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getStorageAll`,
  });
}
