import { createCrudRoutes } from '@d8d/shared-crud';
import { authMiddleware } from '@d8d/auth-module-mt';
import { GoodsMt } from '../entities/goods.entity.mt';
import { AdminGoodsSchema, AdminCreateGoodsDto, AdminUpdateGoodsDto } from '../schemas/admin-goods.schema.mt';
import { FileMt } from '@d8d/file-module-mt';

export const adminGoodsRoutesMt = createCrudRoutes({
  entity: GoodsMt,
  createSchema: AdminCreateGoodsDto,
  updateSchema: AdminUpdateGoodsDto,
  getSchema: AdminGoodsSchema,
  listSchema: AdminGoodsSchema,
  searchFields: ['name', 'instructions'],
  relations: ['category1', 'category2', 'category3', 'supplier', 'imageFile.uploadUser', 'slideImages.uploadUser'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  },
  relationFields: {
    slideImageIds: {
      relationName: 'slideImages',
      targetEntity: FileMt,
      joinTableName: 'goods_slide_images'
    }
  },
  tenantOptions: {
    enabled: true,
    tenantIdField: 'tenantId'
  }
  // 管理员路由不使用数据权限控制，保持完整CRUD功能
});