"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createLambdaHandler = void 0;
const tracing_1 = require("../tracing");
const types_1 = require("../types");
const decorators_1 = require("./decorators");
const getLambdaOptionsFromEnv_1 = require("./getLambdaOptionsFromEnv");
const incomingEvents_1 = require("./incomingEvents");
const createLambdaHandler = (map, environment) => async (event, context) => {
    (0, tracing_1.configureTracer)();
    const { sourceKind, event: eventTyped } = (0, incomingEvents_1.getIncomingEventSourceKind)(event);
    const options = (0, getLambdaOptionsFromEnv_1.getLambdaOptionsFromEnv)();
    switch (sourceKind) {
        case types_1.LambdaEventSourceKind.ApiGatewayV2:
        case types_1.LambdaEventSourceKind.ApiGateway: {
            const handler = (0, decorators_1.decorateApiGatewayEvent)(map.handleApiGatewayEvent, options, environment);
            return handler(eventTyped, context);
        }
        case types_1.LambdaEventSourceKind.Sqs: {
            const handler = (0, decorators_1.decorateSQSEvent)(map.handleSQSEvent, options);
            return handler(eventTyped, context);
        }
        case types_1.LambdaEventSourceKind.RabbitMq: {
            const handler = map.handleRabbitMqEvent;
            return handler(eventTyped, context, options);
        }
        case types_1.LambdaEventSourceKind.CronJob: {
            const handler = map.handleCronJobEvent;
            return handler(eventTyped, context);
        }
        default: {
            throw Error(`Event cannot be handled ${JSON.stringify(event)}`);
        }
    }
};
exports.createLambdaHandler = createLambdaHandler;
//# sourceMappingURL=createLambdaHandler.js.map