import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { FoodCategoryVO, FoodCategoryForm, FoodCategoryQuery } from '@/api/system/foodCategory/types';

/**
 * 查询食材分类列表
 * @param query
 * @returns {*}
 */

export const listFoodCategory = (query?: FoodCategoryQuery): AxiosPromise<FoodCategoryVO[]> => {
  return request({
    url: '/system/foodCategory/list',
    method: 'get',
    params: query
  });
};

export const listTree = (query?: FoodCategoryQuery): AxiosPromise<FoodCategoryVO[]> => {
  return request({
    url: '/system/foodCategory/listTree',
    method: 'get',  
    params: query 
  });
};

/**
 * 查询食材分类详细
 * @param foodCategoryId
 */
export const getFoodCategory = (foodCategoryId: string | number): AxiosPromise<FoodCategoryVO> => {
  return request({
    url: '/system/foodCategory/' + foodCategoryId,
    method: 'get'
  });
};

/**
 * 新增食材分类
 * @param data
 */
export const addFoodCategory = (data: FoodCategoryForm) => {
  return request({
    url: '/system/foodCategory',
    method: 'post',
    data: data
  });
};

/**
 * 修改食材分类
 * @param data
 */
export const updateFoodCategory = (data: FoodCategoryForm) => {
  return request({
    url: '/system/foodCategory',
    method: 'put',
    data: data
  });
};

/**
 * 删除食材分类
 * @param foodCategoryId
 */
export const delFoodCategory = (foodCategoryId: string | number | Array<string | number>) => {
  return request({
    url: '/system/foodCategory/' + foodCategoryId,
    method: 'delete'
  });
};
