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

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

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

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

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

export {
  addPaperCategory,
  deletePaperCategory,
  PaperCategoryOne,
  PaperCategoryTree,
  updatePaperCategory,
};
