import { get, post, put, del, download } from "@/utils/request";

// 知识集列表
export function queryKnowledgeSetsUsingGet(params?: Record<string, unknown>) {
  return get("/api/data-management/knowledge-sets", params);
}

// 知识管理统计
export function getKnowledgeManagementStatisticsUsingGet() {
  return get("/api/data-management/knowledge-sets/statistics");
}

// 创建知识集
export function createKnowledgeSetUsingPost(data: Record<string, unknown>) {
  return post("/api/data-management/knowledge-sets", data);
}

// 获取知识集详情
export function queryKnowledgeSetByIdUsingGet(setId: string) {
  return get(`/api/data-management/knowledge-sets/${setId}`);
}

// 更新知识集
export function updateKnowledgeSetByIdUsingPut(setId: string, data: Record<string, unknown>) {
  return put(`/api/data-management/knowledge-sets/${setId}`, data);
}

// 删除知识集
export function deleteKnowledgeSetByIdUsingDelete(setId: string) {
  return del(`/api/data-management/knowledge-sets/${setId}`);
}

// 知识条目列表
export function queryKnowledgeItemsUsingGet(setId: string, params?: Record<string, unknown>) {
  return get(`/api/data-management/knowledge-sets/${setId}/items`, params);
}

// 知识条目目录列表
export function queryKnowledgeDirectoriesUsingGet(setId: string, params?: Record<string, unknown>) {
  return get(`/api/data-management/knowledge-sets/${setId}/directories`, params);
}

// 创建知识条目目录
export function createKnowledgeDirectoryUsingPost(setId: string, data: Record<string, unknown>) {
  return post(`/api/data-management/knowledge-sets/${setId}/directories`, data);
}

// 删除知识条目目录
export function deleteKnowledgeDirectoryUsingDelete(setId: string, relativePath: string) {
  const query = new URLSearchParams({ relativePath }).toString();
  return del(`/api/data-management/knowledge-sets/${setId}/directories?${query}`);
}

// 知识条目文件搜索
export function searchKnowledgeItemsUsingGet(params?: Record<string, unknown>) {
  return get("/api/data-management/knowledge-items/search", params);
}

// 创建知识条目
export function createKnowledgeItemUsingPost(setId: string, data: Record<string, unknown>) {
  return post(`/api/data-management/knowledge-sets/${setId}/items`, data);
}

// 导入知识条目（数据集文件）
export function importKnowledgeItemsUsingPost(setId: string, data: Record<string, unknown>) {
  return post(`/api/data-management/knowledge-sets/${setId}/items/import`, data);
}

// 获取知识条目详情
export function queryKnowledgeItemByIdUsingGet(setId: string, itemId: string) {
  return get(`/api/data-management/knowledge-sets/${setId}/items/${itemId}`);
}

// 更新知识条目
export function updateKnowledgeItemByIdUsingPut(setId: string, itemId: string, data: Record<string, unknown>) {
  return put(`/api/data-management/knowledge-sets/${setId}/items/${itemId}`, data);
}

// 替换知识条目文件
export function replaceKnowledgeItemFileUsingPut(setId: string, itemId: string, data: FormData) {
  return put(`/api/data-management/knowledge-sets/${setId}/items/${itemId}/file`, data);
}

// 删除知识条目
export function deleteKnowledgeItemByIdUsingDelete(setId: string, itemId: string) {
  return del(`/api/data-management/knowledge-sets/${setId}/items/${itemId}`);
}

// 批量删除知识条目
export function deleteKnowledgeItemsByIdsUsingPost(setId: string, data: { ids: string[] }) {
  return post(`/api/data-management/knowledge-sets/${setId}/items/batch-delete`, data);
}

// 上传知识条目文件
export function uploadKnowledgeItemsUsingPost(setId: string, data: FormData) {
  return post(`/api/data-management/knowledge-sets/${setId}/items/upload`, data);
}

// 下载知识条目文件
export function downloadKnowledgeItemFileUsingGet(setId: string, itemId: string, fileName?: string) {
  return download(`/api/data-management/knowledge-sets/${setId}/items/${itemId}/file`, null, fileName || "");
}

// 知识条目预览状态
export function queryKnowledgeItemPreviewStatusUsingGet(setId: string, itemId: string) {
  return get(`/api/data-management/knowledge-sets/${setId}/items/${itemId}/preview/status`);
}

// 触发知识条目预览转换
export function convertKnowledgeItemPreviewUsingPost(setId: string, itemId: string) {
  return post(`/api/data-management/knowledge-sets/${setId}/items/${itemId}/preview/convert`, {});
}

// 导出知识条目
export function exportKnowledgeItemsUsingGet(setId: string) {
  return download(`/api/data-management/knowledge-sets/${setId}/items/export`);
}
