import { createCrudRoutes } from '@d8d/shared-crud';
import { MerchantMt } from '../entities/merchant.mt.entity';
import { UserMerchantSchemaMt, UserCreateMerchantDtoMt, UserUpdateMerchantDtoMt } from '../schemas/user-merchant.mt.schema';
import { authMiddleware } from '@d8d/auth-module-mt';

// 多租户用户专用商户路由（仅限当前用户使用，包含租户隔离）
export const userMerchantRoutes = createCrudRoutes({
  entity: MerchantMt,
  createSchema: UserCreateMerchantDtoMt,
  updateSchema: UserUpdateMerchantDtoMt,
  getSchema: UserMerchantSchemaMt,
  listSchema: UserMerchantSchemaMt,
  searchFields: ['name', 'username', 'realname', 'phone'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  },
  tenantOptions: {
    tenantIdField: 'tenantId',
    enabled: true
  },
  dataPermission: {
    enabled: true,
    userIdField: 'createdBy',
    adminOverride: {
      enabled: false // 用户路由不允许管理员覆盖
    }
  }
});