const rateLimit = require('express-rate-limit');
// Rate limiting middleware
const createRateLimit = (windowMs, max, message) => {
    return rateLimit({
        windowMs, // Time window in milliseconds
        max, // Maximum number of requests per window
        message: {
            status: 'error',
            message: message || 'Too many requests. Please wait a moment and try again.',
            retryAfter: Math.ceil(windowMs / 1000) // Retry after in seconds
        },
        standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
        legacyHeaders: false, // Disable the `X-RateLimit-*` headers
        handler: (req, res) => {
            res.status(429).json({
                status: 'error',
                message: message || 'Too many requests. Please wait a moment and try again.',
                retryAfter: Math.ceil(windowMs / 1000)
            });
        }
    });
};
// Different rate limits for different endpoints
const authRateLimit = createRateLimit(15 * 60 * 1000, // 15 minutes
5, // 5 login attempts per 15 minutes
'Too many login attempts. Please try again in 15 minutes.');
const generalRateLimit = createRateLimit(15 * 60 * 1000, // 15 minutes
100, // 100 requests per 15 minutes
'Too many requests. Please wait a moment and try again.');
const strictRateLimit = createRateLimit(15 * 60 * 1000, // 15 minutes
50, // 50 requests per 15 minutes
'Too many requests. Please wait a moment and try again.');
const contactRateLimit = createRateLimit(1 * 60 * 1000, // 1 minute
10, // 10 contact operations per minute
'Too many contact operations. Please wait a moment and try again.');
module.exports = {
    authRateLimit,
    generalRateLimit,
    strictRateLimit,
    contactRateLimit
};
//# sourceMappingURL=rateLimiting.js.map