import { createCrudRoutes } from '@d8d/shared-crud';
import { Order } from '../../entities/order.entity';
import { OrderSchema } from '../../schemas/order.schema';
import { UserCreateOrderDto, UserUpdateOrderDto } from '../../schemas/user-order.schema';
import { authMiddleware } from '@d8d/auth-module';

// 用户订单路由 - 有数据权限限制，只能访问自己的订单
const userOrderRoutes = createCrudRoutes({
  entity: Order,
  createSchema: UserCreateOrderDto,
  updateSchema: UserUpdateOrderDto,
  getSchema: OrderSchema,
  listSchema: OrderSchema,
  searchFields: ['orderNo', 'userPhone', 'recevierName'],
  relations: ['user', 'merchant', 'supplier', 'deliveryAddress'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  },
  dataPermission: {
    enabled: true,
    userIdField: 'userId'
  }
});

export default userOrderRoutes;