import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProductCategoryVO, ProductCategoryForm, ProductCategoryQuery } from '@/api/external/productCategory/types';

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

export const listProductCategory = (query?: Partial<ProductCategoryQuery>): AxiosPromise<ProductCategoryVO[]> => {
  return request({
    url: '/external/productCategory/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询产品分类详细
 * @param id
 * @param itemId
 */
export const getProductCategory = (id: string | number, itemId?: string): AxiosPromise<ProductCategoryVO> => {
  return request({
    url: '/external/productCategory/' + id,
    method: 'get',
    params: { itemId }
  });
};

/**
 * 新增产品分类
 * @param data
 */
export const addProductCategory = (data: ProductCategoryForm) => {
  return request({
    url: '/external/productCategory',
    method: 'post',
    data: data
  });
};

/**
 * 修改产品分类
 * @param data
 */
export const updateProductCategory = (data: ProductCategoryForm) => {
  return request({
    url: '/external/productCategory',
    method: 'put',
    data: data
  });
};

/**
 * 删除产品分类
 * @param id
 * @param itemId
 */
export const delProductCategory = (id: string | number | Array<string | number>, itemId?: string) => {
  return request({
    url: '/external/productCategory/' + id,
    method: 'delete',
    params: { itemId }
  });
};

/**
 * 查询产品分类列表（排除指定节点及其子节点）
 * @param id
 * @param itemId
 */
export const listProductCategoryExcludeChild = (id: string | number, itemId?: string): AxiosPromise<ProductCategoryVO[]> => {
  return request({
    url: '/external/productCategory/list/exclude/' + id,
    method: 'get',
    params: { itemId }
  });
};

/**
 * 查询产品分类树结构
 * @param query
 * @returns {*}
 */
export const getProductCategoryTree = (query?: Partial<ProductCategoryQuery>): AxiosPromise<ProductCategoryVO[]> => {
  return request({
    url: '/external/productCategory/categoryTree',
    method: 'get',
    params: query
  });
};
