const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
const require_utils_errors_ErrorHandler = require('./errors/ErrorHandler.cjs');
let express_rate_limit = require("express-rate-limit");
express_rate_limit = require_rolldown_runtime.__toESM(express_rate_limit);

//#region src/utils/rateLimiter.ts
const ipLimiterOptions = {
	windowMs: 60 * 1e3,
	limit: 500,
	standardHeaders: "draft-8",
	legacyHeaders: false,
	keyGenerator: (req) => {
		return (0, express_rate_limit.ipKeyGenerator)(req.ip ?? req.socket?.remoteAddress ?? "unknown");
	},
	handler: (req, res) => {
		const { limit, remaining, resetTime } = req.rateLimit;
		require_utils_errors_ErrorHandler.ErrorHandler.handleGenericErrorResponse(res, "RATE_LIMIT_EXCEEDED", {
			limit: `${limit} per minute`,
			retryAfter: Math.ceil((resetTime?.getTime() - Date.now()) / 1e3),
			remaining
		});
	}
};
const ipLimiter = (0, express_rate_limit.default)(ipLimiterOptions);
const unauthenticatedChatBotLimiterOptions = {
	windowMs: 3600 * 1e3,
	limit: 3,
	standardHeaders: "draft-8",
	skip: (_req, res) => Boolean(res.locals.user),
	legacyHeaders: false,
	keyGenerator: (req) => {
		return (0, express_rate_limit.ipKeyGenerator)(req.ip ?? req.socket?.remoteAddress ?? "unknown");
	},
	handler: (req, res) => {
		const { limit, remaining, resetTime } = req.rateLimit;
		require_utils_errors_ErrorHandler.ErrorHandler.handleGenericErrorResponse(res, "RATE_LIMIT_EXCEEDED_UNAUTHENTICATED", {
			limit: `${limit} per hour`,
			retryAfter: Math.ceil((resetTime?.getTime() - Date.now()) / 1e3),
			remaining
		});
	}
};
const unauthenticatedChatBotLimiter = (0, express_rate_limit.default)(unauthenticatedChatBotLimiterOptions);

//#endregion
exports.ipLimiter = ipLimiter;
exports.unauthenticatedChatBotLimiter = unauthenticatedChatBotLimiter;
//# sourceMappingURL=rateLimiter.cjs.map