import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CategoryVO, CategoryForm, CategoryQuery } from '@/api/product/category/types';

/**
 * 查询产品分类列表
 * @param query
 * @returns {*}
 */

export const listCategory = (query?: CategoryQuery): AxiosPromise<CategoryVO[]> => {
  return request({
    url: '/product/category/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询产品分类详细
 * @param id
 */
export const getCategory = (id: string | number): AxiosPromise<CategoryVO> => {
  return request({
    url: '/product/category/' + id,
    method: 'get'
  });
};

/**
 * 新增产品分类
 * @param data
 */
export const addCategory = (data: CategoryForm) => {
  return request({
    url: '/product/category',
    method: 'post',
    data: data
  });
};

/**
 * 修改产品分类
 * @param data
 */
export const updateCategory = (data: CategoryForm) => {
  return request({
    url: '/product/category',
    method: 'put',
    data: data
  });
};

/**
 * 删除产品分类
 * @param id
 */
export const delCategory = (id: string | number | Array<string | number>) => {
  return request({
    url: '/product/category/' + id,
    method: 'delete'
  });
};

/**
 * 查询产品分类列表（排除节点）
 * @param id
 */
export const listCategoryExcludeChild = (id: string | number): AxiosPromise<CategoryVO[]> => {
  return request({
    url: '/product/category/list/exclude/' + id,
    method: 'get'
  });
};
