/**
 * KRA - Dictionary API Service
 */
import request from '@/utils/request';

export interface Dictionary {
  ID?: number;
  name: string;
  type: string;
  status?: boolean;
  desc?: string;
}

/** 创建字典 */
export const createSysDictionary = (data: Dictionary) => {
  return request.post('/sysDictionary/createSysDictionary', data);
};

/** 删除字典 */
export const deleteSysDictionary = (data: { ID: number }) => {
  return request.delete('/sysDictionary/deleteSysDictionary', { data });
};

/** 更新字典 */
export const updateSysDictionary = (data: Dictionary) => {
  return request.put('/sysDictionary/updateSysDictionary', data);
};

/** 根据ID或type查询字典 */
export const findSysDictionary = (params: { ID?: number; type?: string }) => {
  return request.get('/sysDictionary/findSysDictionary', { params });
};

/** 获取字典列表 */
export const getSysDictionaryList = (params?: { name?: string; type?: string; status?: boolean; desc?: string }) => {
  return request.get('/sysDictionary/getSysDictionaryList', { params });
};

/** 导出字典JSON */
export const exportSysDictionary = (params: { ID: number }) => {
  return request.get('/sysDictionary/exportSysDictionary', { params });
};

/** 导入字典JSON */
export const importSysDictionary = (data: any) => {
  return request.post('/sysDictionary/importSysDictionary', data);
};

// 别名导出，兼容页面调用
export const getDictionaryList = getSysDictionaryList;

export default {
  createSysDictionary,
  deleteSysDictionary,
  updateSysDictionary,
  findSysDictionary,
  getSysDictionaryList,
  exportSysDictionary,
  importSysDictionary,
  getDictionaryList,
};
