import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { NutritionVO, NutritionForm, NutritionQuery } from '@/api/warehouse/productNutrition/types';

/**
 * 查询营养产品信息列表
 * @param query
 * @returns {*}
 */

export const listNutrition = (query?: NutritionQuery): AxiosPromise<NutritionVO[]> => {
  return request({
    url: '/warehouse/nutrition/list',
    method: 'get',
    params: query
  });
};

export const listAllNutrition = (): AxiosPromise<NutritionVO[]> => {
  return request({
    url: '/warehouse/nutrition/listAll',
    method: 'get'
  });
};

/**
 * 查询营养产品信息详细
 * @param id
 */
export const getNutrition = (id: string | number): AxiosPromise<NutritionVO> => {
  return request({
    url: '/warehouse/nutrition/' + id,
    method: 'get'
  });
};

/**
 * 新增营养产品信息
 * @param data
 */
export const addNutrition = (data: NutritionForm) => {
  return request({
    url: '/warehouse/nutrition',
    method: 'post',
    data: data
  });
};

/**
 * 修改营养产品信息
 * @param data
 */
export const updateNutrition = (data: NutritionForm) => {
  return request({
    url: '/warehouse/nutrition',
    method: 'put',
    data: data
  });
};

export function batchUpdateNutrition(data) {
  return request({
    url: '/warehouse/nutrition/batchUpdate',
    method: 'post',
    data
  });
}

/**
 * 删除营养产品信息
 * @param id
 */
export const delNutrition = (id: string | number | Array<string | number>) => {
  return request({
    url: '/warehouse/nutrition/' + id,
    method: 'delete'
  });
};
