import { createCrudRoutes } from '@d8d/shared-crud';
import { OrderMt } from '../../entities/order.mt.entity';
import { OrderSchema, CreateOrderDto, UpdateOrderDto } from '../../schemas/order.mt.schema';
import { authMiddleware } from '@d8d/auth-module-mt';

// 多租户管理员订单路由 - 无数据权限限制，完整CRUD功能
const adminOrderRoutes = createCrudRoutes({
  entity: OrderMt,
  createSchema: CreateOrderDto,
  updateSchema: UpdateOrderDto,
  getSchema: OrderSchema,
  listSchema: OrderSchema,
  searchFields: ['orderNo', 'userPhone', 'recevierName'],
  relations: ['user', 'merchant', 'supplier', 'deliveryAddress', 'orderGoods.imageFile'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  },
  tenantOptions: {
    enabled: true,
    tenantIdField: 'tenantId'
  }
  // 管理员路由不设置dataPermission，可以访问所有数据
});

export default adminOrderRoutes;