import { createCrudRoutes } from '@d8d/shared-crud';
import { MerchantMt } from '../entities/merchant.mt.entity';
import { AdminMerchantSchemaMt, AdminCreateMerchantDtoMt, AdminUpdateMerchantDtoMt } from '../schemas/admin-merchant.mt.schema';
import { authMiddleware } from '@d8d/auth-module-mt';

// 多租户管理员专用商户路由（完整权限，包含租户隔离）
export const adminMerchantRoutes = createCrudRoutes({
  entity: MerchantMt,
  createSchema: AdminCreateMerchantDtoMt,
  updateSchema: AdminUpdateMerchantDtoMt,
  getSchema: AdminMerchantSchemaMt,
  listSchema: AdminMerchantSchemaMt,
  searchFields: ['name', 'username', 'realname', 'phone'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  },
  tenantOptions: {
    tenantIdField: 'tenantId',
    enabled: true
  },
  dataPermission: {
    enabled: false, // 管理员路由不使用数据权限控制
    userIdField: 'createdBy' // 即使不启用，也需要提供userIdField
  }
});