import { requestClient } from '#/api/request';

enum Api {
  base = '/examCategory/category',
  tree = '/examCategory/category/list',
}

export interface ExamCategory {
  children: ExamCategory[];
  id: number;
  name: string;
  parentId: number;
  icon: string;
  description: string;
  sortOrder: number;
  delFlag: string;
}

/**
 * 获取试题分类树形图
 */
async function examCategoryTree() {
  return requestClient.get<ExamCategory[]>(Api.tree);
}

async function examCategoryOne(id: number) {
  return requestClient.get<ExamCategory>(`${Api.base}/${id}`);
}
// 新增试题分类
function addExamCategory(category: ExamCategory) {
  return requestClient.post(Api.base, category, {
    successMessageMode: 'message',
  });
}
// 修改试题分类
function updateExamCategory(category: ExamCategory) {
  return requestClient.put(Api.base, category, {
    successMessageMode: 'message',
  });
}
// 删除试题分类
function deleteExamCategory(categoryId: number) {
  return requestClient.delete(`${Api.base}/${categoryId}`, {
    successMessageMode: 'message',
  });
}

export {
  addExamCategory,
  deleteExamCategory,
  examCategoryOne,
  examCategoryTree,
  updateExamCategory,
};
