import type { FastifyInstance } from 'fastify';
import * as knowledgeBaseController from '../controllers/knowledgeBaseController.js';
import * as documentController from '../controllers/documentController.js';

export default async function knowledgeBaseRoutes(fastify: FastifyInstance) {
  // ==================== 知识库管理 API ====================

  // 创建知识库
  fastify.post('/knowledge-bases', knowledgeBaseController.createKnowledgeBase);

  // 获取知识库列表
  fastify.get('/knowledge-bases', knowledgeBaseController.getKnowledgeBases);

  // 获取知识库详情
  fastify.get('/knowledge-bases/:id', knowledgeBaseController.getKnowledgeBaseById);

  // 更新知识库
  fastify.put('/knowledge-bases/:id', knowledgeBaseController.updateKnowledgeBase);

  // 删除知识库
  fastify.delete('/knowledge-bases/:id', knowledgeBaseController.deleteKnowledgeBase);

  // 检索知识库
  fastify.get('/knowledge-bases/:id/search', knowledgeBaseController.searchKnowledgeBase);

  // 获取知识库统计信息
  fastify.get('/knowledge-bases/:id/stats', knowledgeBaseController.getKnowledgeBaseStats);

  // Phase 2: 获取文档选择（全文阅读模式）
  fastify.get('/knowledge-bases/:id/document-selection', knowledgeBaseController.getDocumentSelection);

  // ==================== 文档管理 API ====================

  // 上传文档
  fastify.post('/knowledge-bases/:kbId/documents', documentController.uploadDocument);

  // 获取文档列表
  fastify.get('/knowledge-bases/:kbId/documents', documentController.getDocuments);

  // 获取文档详情
  fastify.get('/documents/:id', documentController.getDocumentById);

  // Phase 2: 获取文档全文
  fastify.get('/documents/:id/full-text', documentController.getDocumentFullText);

  // 删除文档
  fastify.delete('/documents/:id', documentController.deleteDocument);

  // 重新处理文档
  fastify.post('/documents/:id/reprocess', documentController.reprocessDocument);
}


