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

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

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

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

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

export {
  addQuestionCategory,
  deleteQuestionCategory,
  questionCategoryOne,
  questionCategoryTree,
  updateQuestionCategory,
};
