import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
import { ChatMessage } from '@/server/modules/chat/chat-message.entity';
import { 
  ChatMessageSchema, 
  CreateChatMessageDto, 
  UpdateChatMessageDto
} from '@/server/modules/chat/chat-message.schema';
import { authMiddleware } from '@/server/middleware/auth.middleware';
import { OpenAPIHono } from '@hono/zod-openapi';
import historyRoute from './history';

// 创建基础CRUD路由
const crudRoutes = createCrudRoutes({
  entity: ChatMessage,
  createSchema: CreateChatMessageDto,
  updateSchema: UpdateChatMessageDto,
  getSchema: ChatMessageSchema,
  listSchema: ChatMessageSchema,
  searchFields: ['content', 'senderName'],
  relations: ['file', 'sender'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  }
});

// 创建聚合路由
const app = new OpenAPIHono()
  .route('/', historyRoute)
  .route('/', crudRoutes);

export default app;