import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PersonalEnteralNutritionTemplateVO, PersonalEnteralNutritionTemplateForm, PersonalEnteralNutritionTemplateQuery } from '@/api/parameter/personalTemplate/enteralNutritionTemplate/types';

/**
 * 查询个人肠内处方模板列表
 * @param query
 * @returns {*}
 */
export const listPersonalEnteralNutritionTemplate = (query?: PersonalEnteralNutritionTemplateQuery): AxiosPromise<PersonalEnteralNutritionTemplateVO[]> => {
  // 使用与基础公共模板相同的接口，通过templateType=0区分个人模板
  const params = { ...query, templateType: 0 };
  return request({
    url: '/parameter/basicPublicTemplate/enteralNutritionTemplate/list',
    method: 'get',
    params: params
  });
};

/**
 * 查询个人肠内处方模板详细
 * @param id
 */
export const getPersonalEnteralNutritionTemplate = (id: string | number): AxiosPromise<PersonalEnteralNutritionTemplateVO> => {
  return request({
    url: '/parameter/basicPublicTemplate/enteralNutritionTemplate/' + id,
    method: 'get'
  });
};

/**
 * 新增个人肠内处方模板
 * @param data
 */
export const addPersonalEnteralNutritionTemplate = (data: PersonalEnteralNutritionTemplateForm) => {
  // 确保设置为个人模板类型
  const formData = { ...data, templateType: 0 };
  return request({
    url: '/parameter/basicPublicTemplate/enteralNutritionTemplate',
    method: 'post',
    data: formData
  });
};

/**
 * 修改个人肠内处方模板
 * @param data
 */
export const updatePersonalEnteralNutritionTemplate = (data: PersonalEnteralNutritionTemplateForm) => {
  // 确保设置为个人模板类型
  const formData = { ...data, templateType: 0 };
  return request({
    url: '/parameter/basicPublicTemplate/enteralNutritionTemplate',
    method: 'put',
    data: formData
  });
};

/**
 * 查询所有个人肠内处方模板（不分页）
 * @returns {*}
 */
export const listAllPersonalEnteralNutritionTemplate = (): AxiosPromise<PersonalEnteralNutritionTemplateVO[]> => {
  return request({
    url: '/parameter/basicPublicTemplate/enteralNutritionTemplate/listAll',
    method: 'get',
    params: { templateType: 0 }
  });
};

/**
 * 删除个人肠内处方模板
 * @param id
 */
export const delPersonalEnteralNutritionTemplate = (id: string | number | Array<string | number>) => {
  return request({
    url: '/parameter/basicPublicTemplate/enteralNutritionTemplate/' + id,
    method: 'delete'
  });
}; 