"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "slicerApiKeyAuth", {
    enumerable: true,
    get: function() {
        return slicerApiKeyAuth;
    }
});
const _awilixexpress = require("awilix-express");
const _runtimeexceptions = require("../exceptions/runtime.exceptions");
const slicerApiKeyAuth = ()=>(0, _awilixexpress.inject)((loggerFactory, settingsStore)=>async (req, res, next)=>{
            const logger = loggerFactory("Middleware:slicerApiKeyAuth");
            const apiKey = req.headers["x-api-key"];
            if (!apiKey?.length) {
                throw new _runtimeexceptions.AuthenticationError("Header x-api-key is missing");
            }
            const isValid = settingsStore.validateSlicerApiKey(apiKey);
            if (isValid) {
                logger.log(`Slicer API key authentication successful for ${req.originalUrl}`);
                req.slicerApiKeyAuthenticated = true;
                return next();
            }
            logger.warn(`Invalid slicer API key provided for ${req.originalUrl}`);
            throw new _runtimeexceptions.AuthenticationError("Header x-api-key is wrong");
        });

//# sourceMappingURL=slicer-api-key.middleware.js.map