"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCustomLimiter = exports.templateLimiter = exports.bulkLimiter = exports.strictLimiter = exports.generalLimiter = void 0;
const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
/**
 * General rate limiter for all API endpoints
 * 100 requests per 15 minutes per IP
 */
exports.generalLimiter = (0, express_rate_limit_1.default)({
    windowMs: 15 * 60 * 1000, // 15 minutes
    max: 100, // Limit each IP to 100 requests per windowMs
    message: {
        success: false,
        error: 'Too many requests from this IP, please try again later.',
        retryAfter: '15 minutes'
    },
    standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
    legacyHeaders: false, // Disable the `X-RateLimit-*` headers
    skipSuccessfulRequests: false,
    keyGenerator: (req) => {
        // Use IP address as the key
        return req.ip || 'unknown';
    }
});
/**
 * Strict rate limiter for create/update/delete operations
 * 20 requests per 15 minutes per IP
 */
exports.strictLimiter = (0, express_rate_limit_1.default)({
    windowMs: 15 * 60 * 1000, // 15 minutes
    max: 20, // Limit each IP to 20 requests per windowMs
    message: {
        success: false,
        error: 'Too many write operations from this IP, please try again later.',
        retryAfter: '15 minutes'
    },
    standardHeaders: true,
    legacyHeaders: false,
    skipSuccessfulRequests: false,
    keyGenerator: (req) => {
        return req.ip || 'unknown';
    }
});
/**
 * Bulk operations rate limiter
 * 10 requests per 15 minutes per IP
 */
exports.bulkLimiter = (0, express_rate_limit_1.default)({
    windowMs: 15 * 60 * 1000, // 15 minutes
    max: 10, // Limit each IP to 10 bulk requests per windowMs
    message: {
        success: false,
        error: 'Too many bulk operations from this IP, please try again later.',
        retryAfter: '15 minutes'
    },
    standardHeaders: true,
    legacyHeaders: false,
    skipSuccessfulRequests: false,
    keyGenerator: (req) => {
        return req.ip || 'unknown';
    }
});
/**
 * Template operations rate limiter
 * 30 requests per 15 minutes per IP
 */
exports.templateLimiter = (0, express_rate_limit_1.default)({
    windowMs: 15 * 60 * 1000, // 15 minutes
    max: 30, // Limit each IP to 30 template requests per windowMs
    message: {
        success: false,
        error: 'Too many template operations from this IP, please try again later.',
        retryAfter: '15 minutes'
    },
    standardHeaders: true,
    legacyHeaders: false,
    skipSuccessfulRequests: false,
    keyGenerator: (req) => {
        return req.ip || 'unknown';
    }
});
/**
 * Create a custom rate limiter with specific settings
 */
const createCustomLimiter = (windowMs, max, message) => {
    return (0, express_rate_limit_1.default)({
        windowMs,
        max,
        message: {
            success: false,
            error: message,
            retryAfter: `${windowMs / 60000} minutes`
        },
        standardHeaders: true,
        legacyHeaders: false,
        skipSuccessfulRequests: false,
        keyGenerator: (req) => {
            return req.ip || 'unknown';
        }
    });
};
exports.createCustomLimiter = createCustomLimiter;
//# sourceMappingURL=rateLimit.middleware.js.map