import { createCrudRoutes } from '@d8d/shared-crud';
import { OpenAPIHono } from '@hono/zod-openapi';
import { Order } from '../../entities/order.entity';
import { OrderSchema, CreateOrderDto, UpdateOrderDto } from '../../schemas/order.schema';
import { authMiddleware } from '@d8d/auth-module';

// 管理员订单路由 - 无数据权限限制，完整CRUD功能
const adminOrderRoutes = 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'
  }
  // 管理员路由不设置dataPermission，可以访问所有数据
});

export default adminOrderRoutes;