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

export interface DictionaryDetail {
  ID?: number;
  sysDictionaryID: number;
  parentID?: number;
  label: string;
  value: any;
  extend?: string;
  status?: boolean;
  sort?: number;
  children?: DictionaryDetail[];
}

/** 创建字典详情 */
export const createSysDictionaryDetail = (data: DictionaryDetail) => {
  return request.post('/sysDictionaryDetail/createSysDictionaryDetail', data);
};

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

/** 更新字典详情 */
export const updateSysDictionaryDetail = (data: DictionaryDetail) => {
  return request.put('/sysDictionaryDetail/updateSysDictionaryDetail', data);
};

/** 根据ID查询字典详情 */
export const findSysDictionaryDetail = (params: { ID: number }) => {
  return request.get('/sysDictionaryDetail/findSysDictionaryDetail', { params });
};

/** 获取字典详情列表 */
export const getSysDictionaryDetailList = (params: { page: number; pageSize: number; sysDictionaryID?: number; label?: string; value?: any; status?: boolean }) => {
  return request.get('/sysDictionaryDetail/getSysDictionaryDetailList', { params });
};

/** 获取字典树形结构（根据字典ID） */
export const getDictionaryTreeList = (params: { sysDictionaryID: number }) => {
  return request.get('/sysDictionaryDetail/getDictionaryTreeList', { params });
};

/** 获取字典树形结构（根据字典类型） */
export const getDictionaryTreeListByType = (params: { type: string }) => {
  return request.get('/sysDictionaryDetail/getDictionaryTreeListByType', { params });
};

/** 根据父级ID获取字典详情 */
export const getDictionaryDetailsByParent = (params: { parentID: number; includeChildren?: boolean }) => {
  return request.get('/sysDictionaryDetail/getDictionaryDetailsByParent', { params });
};

/** 获取字典详情完整路径 */
export const getDictionaryPath = (params: { ID: number }) => {
  return request.get('/sysDictionaryDetail/getDictionaryPath', { params });
};

// 别名导出，兼容页面调用
export const getDictionaryDetailList = getSysDictionaryDetailList;
export const createDictionaryDetail = createSysDictionaryDetail;
export const updateDictionaryDetail = updateSysDictionaryDetail;
export const deleteDictionaryDetail = deleteSysDictionaryDetail;
export const findDictionaryDetail = findSysDictionaryDetail;

export default {
  createSysDictionaryDetail,
  deleteSysDictionaryDetail,
  updateSysDictionaryDetail,
  findSysDictionaryDetail,
  getSysDictionaryDetailList,
  getDictionaryTreeList,
  getDictionaryTreeListByType,
  getDictionaryDetailsByParent,
  getDictionaryPath,
  getDictionaryDetailList,
  createDictionaryDetail,
  updateDictionaryDetail,
  deleteDictionaryDetail,
  findDictionaryDetail,
};
