"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.respond = void 0;
/**
 * This function is just a wrapper that builds the response that api gateway wants
 * TODO:- Probably might be worth adding the right type for allowed status codes
 */
function respond(statusCode, response, headers, isBase64Encoded) {
    var result = {
        statusCode: statusCode,
        body: JSON.stringify(response),
    };
    /**
     * The next sections parses out single value and multi values headers from headers
     * This makes it easy to send out the response
     */
    var singleValueHeaders = {};
    var multiValueHeaders = {};
    if (headers) {
        Object.keys(headers).forEach(function (header) {
            var value = headers[header];
            if (Array.isArray(value)) {
                multiValueHeaders[header] = value;
            }
            else {
                singleValueHeaders[header] = value;
            }
        });
    }
    if (Object.keys(singleValueHeaders).length > 0) {
        result.headers = singleValueHeaders;
    }
    if (Object.keys(multiValueHeaders).length > 0) {
        result.multiValueHeaders = multiValueHeaders;
    }
    if (typeof isBase64Encoded === "boolean") {
        result.isBase64Encoded = isBase64Encoded;
    }
    return result;
}
exports.respond = respond;
//# sourceMappingURL=api-gateway.js.map