import {
  AddGoodsParams,
  BaseListResult,
  BaseResult,
  EditGoodsParams,
  GetGoodsListParams,
  GoodsListData,
} from '@models';
import {request} from './request';

const BASE_URL = '/goods';

/** 查询商品列表 */
export function getGoodsList(data: GetGoodsListParams): BaseListResult<GoodsListData> {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/getGoods`,
  });
}

/** 获取商品详细信息 */
export function getGoodsInfo(id: string): BaseListResult<GoodsListData> {
  return request({
    method: 'GET',
    data: {
      page: '1',
      limit: '1',
      id,
    },
    url: `${BASE_URL}/getGoods`,
  });
}

/** 新增商品信息 */
export function addGoods(data: AddGoodsParams): BaseResult {
  return request({
    data,
    method: 'POST',
    url: `${BASE_URL}/addGoods`,
  });
}

/** 修改商品信息 */
export function editGoods(data: EditGoodsParams): BaseResult {
  return request({
    method: 'PUT',
    url: `${BASE_URL}/updateGoods`,
    data,
  });
}

/** 删除商品信息 */
export function deleteGoods(id: string): BaseResult {
  return request({
    method: 'DELETE',
    data: {id},
    url: `${BASE_URL}/delGoods`,
  });
}

/** 导出商品 */
export function goodsExport(data: GetGoodsListParams): any {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/export`,
    skipError: true,
  });
}
