import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { UnitVO, UnitForm, UnitQuery } from '@/api/product/unit/types';

/**
 * 查询产品计量单位列表
 * @param query
 * @returns {*}
 */

export const listUnit = (query?: UnitQuery): AxiosPromise<UnitVO[]> => {
  return request({
    url: '/product/unit/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询产品计量单位详细
 * @param id
 */
export const getUnit = (id: string | number): AxiosPromise<UnitVO> => {
  return request({
    url: '/product/unit/' + id,
    method: 'get'
  });
};

/**
 * 新增产品计量单位
 * @param data
 */
export const addUnit = (data: UnitForm) => {
  return request({
    url: '/product/unit',
    method: 'post',
    data: data
  });
};

/**
 * 修改产品计量单位
 * @param data
 */
export const updateUnit = (data: UnitForm) => {
  return request({
    url: '/product/unit',
    method: 'put',
    data: data
  });
};

/**
 * 删除产品计量单位
 * @param id
 */
export const delUnit = (id: string | number | Array<string | number>) => {
  return request({
    url: '/product/unit/' + id,
    method: 'delete'
  });
};
