import { createCrudRoutes } from '@d8d/shared-crud';
import { OpenAPIHono } from '@hono/zod-openapi';
import { OrderGoods } from '../../entities/order-goods.entity';
import { OrderGoodsSchema, CreateOrderGoodsDto, UpdateOrderGoodsDto } from '../../schemas/order-goods.schema';
import { authMiddleware } from '@d8d/auth-module';

// 管理员订单商品路由 - 无数据权限限制，完整CRUD功能
const adminOrderItemsRoutes = createCrudRoutes({
  entity: OrderGoods,
  createSchema: CreateOrderGoodsDto,
  updateSchema: UpdateOrderGoodsDto,
  getSchema: OrderGoodsSchema,
  listSchema: OrderGoodsSchema,
  searchFields: ['orderNo', 'goodsName'],
  relations: ['order', 'goods', 'supplier', 'imageFile'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  }
  // 管理员路由不设置dataPermission，可以访问所有数据
});

export default adminOrderItemsRoutes;