/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2025-05-28 11:11:21
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2025-07-03 15:55:44
 * @FilePath: /pfmBackMana/src/pages/checkConditionMana/service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * @Description: 条件管理服务
 */

import { request } from 'umi';

// 获取条件列表数据
export const getConditionList = (params?: any) => {
  return request('/manager/FilterCondition/getSysFilterConditionList', {
    method: 'GET',
    params: { ...params },
  });
};

// 获取条件分类列表
export const getConditionDeptClassList = (params: {
  filterConditionId: string | number;
  filter?: string;
  page?: number;
  pageSize?: number;
}) => {
  return request('/manager/FilterCondition/getFilterConditionDeptclassList', {
    method: 'GET',
    params,
  });
};

// 保存条件分类关联
export const saveConditionDeptClass = (data: {
  id: string;
  mapIdList: (string | number)[];
}) => {
  return request('/manager/FilterCondition/applyFilterConditionDeptclass', {
    method: 'POST',
    data,
  });
};

// 新增条件数据
export type AddConditionType = {
  name: string; // 条件名称
  parentId?: number; // 父级条件id
  parentName?: string; // 父级条件名称
  conditionType: string; // 条件类型：0个案/1系统
  description: string; // 说明
  sortNo: number; // 顺序号
  depType: number; // 门诊类型：1门诊/2急诊
  checkType: number; // 是否自宣督查：0否/1是
  // 个案追踪专用字段
  required?: number; // 是否必填：0否/1是
  multiple?: number; // 选择类型：0不选/1单选/2多选
  initialize?: number; // 是否初显：0否/1是
  subOptions?: number; // 是否有子选项：0无/1有
  subOptionId?: number; // 子选项id
};

export const addCondition = (data: AddConditionType) => {
  return request('/manager/FilterCondition/addSysFilterCondition', {
    method: 'POST',
    data,
  });
};

// 编辑条件数据
export const editCondition = (data: { id: number } & AddConditionType) => {
  return request('/manager/FilterCondition/updateSysFilterCondition', {
    method: 'POST',
    data,
  });
};

// 删除条件
export const delCondition = (id: string | number | (string | number)[]) => {
  // 如果传入的是数组，直接使用；否则包装成数组
  const idsArray = Array.isArray(id) ? id : [id];
  return request('/manager/FilterCondition/deleteSysFilterCondition', {
    method: 'POST',
    data: idsArray, // 入参格式是数组
  });
};

// 添加子条件
export const addSubCondition = (data: any) => {
  return request('/manager/FilterCondition/addSubFilterCondition', {
    method: 'POST',
    data,
  });
};
