"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const deepmerge = __importStar(require("deepmerge"));
/**
 * Merges a list of ConfigParseResults into a single ParseResult, with a single sls-congiguration
 *
 * @param results
 */
function mergeParseResults(results) {
    //console.log("mergeParseResults: ", results);
    return results.reduce((merged, item) => {
        //console.log("afterMerge: ", merged.slsConfigs);
        //console.log("mergeParseResults: ", item.slsConfigs);
        return {
            slsConfigs: deepmerge.all([
                ...(Array.isArray(item.slsConfigs) ? item.slsConfigs : [item.slsConfigs])
            ], merged.slsConfigs),
            webpackConfigs: merged.webpackConfigs.concat(item.webpackConfigs),
            postBuilds: merged.postBuilds.concat(item.postBuilds),
            environments: (merged.environments !== undefined ? merged.environments : []).concat(item.environments !== undefined ? item.environments : []),
            // the iamRoleStatements must be processed in the App already!, e.g. IsomorphicApp
            iamRoleStatements: [],
            // usually, these fields should not be defined here, but only from the top-level configuration
            stackName: item.stackName !== undefined ? item.stackName : merged.stackName,
            assetsPath: item.assetsPath !== undefined ? item.assetsPath : merged.assetsPath,
            buildPath: item.buildPath !== undefined ? item.buildPath : merged.buildPath,
            region: item.region !== undefined ? item.region : merged.region,
            domain: item.domain !== undefined ? item.domain : merged.domain,
            certArn: item.certArn !== undefined ? item.certArn : merged.certArn,
            supportOfflineStart: item.supportOfflineStart !== undefined ? item.supportOfflineStart : merged.supportOfflineStart,
            supportCreateDomain: item.supportCreateDomain !== undefined ? item.supportCreateDomain : merged.supportCreateDomain
        };
    }, {
        slsConfigs: {},
        webpackConfigs: [],
        postBuilds: []
    });
}
exports.mergeParseResults = mergeParseResults;
//# sourceMappingURL=config-parse-result.js.map