import { createCrudRoutes } from '../../utils/generic-crud.routes';
import { OpenAPIHono } from '@hono/zod-openapi';
import { Order } from '../../modules/orders/order.entity';
import { OrderSchema, CreateOrderDto, UpdateOrderDto } from '../../modules/orders/order.schema';
import { authMiddleware } from '../../middleware/auth.middleware';

// 基础CRUD路由
const orderRoutes = createCrudRoutes({
  entity: Order,
  createSchema: CreateOrderDto,
  updateSchema: UpdateOrderDto,
  getSchema: OrderSchema,
  listSchema: OrderSchema,
  searchFields: ['orderNo', 'userPhone', 'recevierName'],
  relations: ['user', 'merchant', 'supplier', 'deliveryAddress'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  }
});

// 导入扩展路由
import createOrderRoute from './create-order';

// 聚合所有路由
const app = new OpenAPIHono()
  .route('/create-order', createOrderRoute)  // 创建订单专用路由
  .route('/', orderRoutes);  // 基础CRUD路由

export default app;