import { createCrudRoutes } from '@d8d/shared-crud';
import { Merchant } from '../entities/merchant.entity';
import { UserMerchantSchema, UserCreateMerchantDto, UserUpdateMerchantDto } from '../schemas/user-merchant.schema';
import { authMiddleware } from '@d8d/auth-module';

// 用户专用商户路由（仅限当前用户使用）
export const userMerchantRoutes = createCrudRoutes({
  entity: Merchant,
  createSchema: UserCreateMerchantDto,
  updateSchema: UserUpdateMerchantDto,
  getSchema: UserMerchantSchema,
  listSchema: UserMerchantSchema,
  searchFields: ['name', 'username', 'realname', 'phone'],
  middleware: [authMiddleware],
  userTracking: {
    createdByField: 'createdBy',
    updatedByField: 'updatedBy'
  },
  dataPermission: {
    enabled: true,
    userIdField: 'createdBy',
    adminOverride: {
      enabled: false // 用户路由不允许管理员覆盖
    }
  }
});