const rateLimit = require('express-rate-limit');

// 通用限流器 - 100请求/分钟
const standardLimiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  message: { error: '请求过于频繁，请稍后再试' },
  standardHeaders: true,
  legacyHeaders: false,
});

// 认证限流器 - 10请求/分钟 (防止暴力攻击)
const authLimiter = rateLimit({
  windowMs: 60 * 1000,
  max: 10,
  message: { error: '登录尝试过于频繁，请稍后再试' },
  standardHeaders: true,
  legacyHeaders: false,
});

// OCR限流器 - 5请求/分钟 (OCR是重操作)
const ocrLimiter = rateLimit({
  windowMs: 60 * 1000,
  max: 5,
  message: { error: 'OCR处理请求过于频繁，请稍后再试' },
  standardHeaders: true,
  legacyHeaders: false,
});

// 彩票刷新限流器 - 10请求/分钟
const refreshLimiter = rateLimit({
  windowMs: 60 * 1000,
  max: 10,
  message: { error: '刷新请求过于频繁，请稍后再试' },
  standardHeaders: true,
  legacyHeaders: false,
});

module.exports = { standardLimiter, authLimiter, ocrLimiter, refreshLimiter };
