import rateLimit from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
import { redis } from '../../config/redis';

/** Friend request rate limit: 10 per minute */
export const friendRequestRateLimit = rateLimit({
  windowMs: 60 * 1000,
  max: 10,
  standardHeaders: true,
  legacyHeaders: false,
  store: new RedisStore({
    sendCommand: (command: string, ...args: string[]) => redis.call(command, ...args) as Promise<any>,
    prefix: 'rl:friend-request:',
  }),
  message: {
    error: {
      message: 'Too many friend requests, please try again later',
      code: 'FRIEND_REQUEST_RATE_LIMIT_EXCEEDED',
    },
  },
});

/** Social action rate limit: 30 per minute (blocks, pokes, etc.) */
export const socialActionRateLimit = rateLimit({
  windowMs: 60 * 1000,
  max: 30,
  standardHeaders: true,
  legacyHeaders: false,
  store: new RedisStore({
    sendCommand: (command: string, ...args: string[]) => redis.call(command, ...args) as Promise<any>,
    prefix: 'rl:social-action:',
  }),
  message: {
    error: {
      message: 'Too many social actions, please slow down',
      code: 'SOCIAL_ACTION_RATE_LIMIT_EXCEEDED',
    },
  },
});
