import { SetMetadata } from '@nestjs/common';
import { type UserRole } from '@prisma/client';
import { USER_RATE_LIMIT_KEY, type UserRateLimitOptions } from '../guards/user-rate-limit.guard';

/**
 * Decorator to override per-user rate limits for a specific route or controller.
 *
 * When not applied, the UserRateLimitGuard uses DEFAULT_ROLE_LIMITS.
 *
 * @example
 * // Override BUYER limit to 50 req/min for an expensive endpoint
 * @UserRateLimit({ limits: { BUYER: 50 }, windowSeconds: 60 })
 *
 * @example
 * // Allow higher limits for a specific route
 * @UserRateLimit({ limits: { BUYER: 200, AGENT: 400 } })
 */
export const UserRateLimit = (options: {
  limits?: Partial<Record<UserRole, number>>;
  windowSeconds?: number;
}) => SetMetadata<string, UserRateLimitOptions>(USER_RATE_LIMIT_KEY, options);
