"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.exchangeRateLimiter = void 0;
const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
const integration_foundation_1 = require("@dbis/integration-foundation");
function asHandler(h) {
    return h;
}
exports.exchangeRateLimiter = asHandler((0, express_rate_limit_1.default)({
    windowMs: 60_000,
    max: (req) => {
        if (!(0, integration_foundation_1.isProductionSecurityMode)())
            return 200;
        const policy = (0, integration_foundation_1.loadCustomerSecurityPolicy)();
        const principal = (0, integration_foundation_1.resolveOmnlPrincipal)(req);
        if (!principal)
            return policy.rateLimits.anonymousPerMinute;
        if (principal.role === 'customer')
            return policy.rateLimits.customerPerMinute;
        return policy.rateLimits.superAdminPerMinute;
    },
    message: { error: 'Too many requests — rate limit exceeded' },
    standardHeaders: true,
    legacyHeaders: false,
}));
