import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { GoodsVO, GoodsQuery, GoodsForm } from './types';

/**
 * 查询商品列表
 * @param query
 * @returns {*}
 */
export const listGoods = (query: GoodsQuery): AxiosPromise<GoodsVO[]> => {
  return request({
    url: '/main/goods/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询商品详细
 * @param id
 * @returns {*}
 */
export const getGoods = (id: string | number): AxiosPromise<GoodsVO> => {
  return request({
    url: '/main/goods/' + id,
    method: 'get'
  });
};

/**
 * 新增商品
 * @param data
 * @returns {*}
 */
export const addGoods = (data: GoodsForm) => {
  return request({
    url: '/main/goods',
    method: 'post',
    data: data
  });
};

/**
 * 修改商品
 * @param data
 * @returns {*}
 */
export const updateGoods = (data: GoodsForm) => {
  return request({
    url: '/main/goods',
    method: 'put',
    data: data
  });
};

/**
 * 删除商品
 * @param id
 * @returns {*}
 */
export const delGoods = (id: string | number | Array<string | number>) => {
  return request({
    url: '/main/goods/' + id,
    method: 'delete'
  });
};
