"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renameInApplicationConfiguration = renameInApplicationConfiguration;
const lodash_1 = require("lodash");
const updates_js_1 = require("./updates.js");
async function renameInApplicationConfiguration({ dsl, oldName, newName, dataTree, extractPairs, namespace }) {
    const newDSL = (0, lodash_1.cloneDeep)(dsl);
    if (!newDSL) {
        return dsl;
    }
    let updates = [];
    if (newDSL?.events?.eventMap) {
        const eventUpdates = await (0, updates_js_1.updateNameInEntityMap)({
            entityMap: newDSL?.events,
            dataTree,
            newName,
            oldName,
            namespace,
            parentKey: 'events',
            extractPairs
        });
        updates = [...updates, ...eventUpdates];
    }
    if (newDSL?.timers?.timerMap) {
        const timerUpdates = await (0, updates_js_1.updateNameInEntityMap)({
            entityMap: newDSL?.timers,
            dataTree,
            newName,
            oldName,
            namespace,
            parentKey: 'timers',
            extractPairs
        });
        updates = [...updates, ...timerUpdates];
    }
    if (newDSL?.stateVars?.stateVarMap) {
        const stateVarUpdates = await (0, updates_js_1.updateNameInEntityMap)({
            entityMap: newDSL?.stateVars,
            dataTree,
            newName,
            oldName,
            namespace,
            parentKey: 'stateVars',
            extractPairs
        });
        updates = [...updates, ...stateVarUpdates];
    }
    updates.forEach((update) => (0, lodash_1.set)(newDSL, update.propertyName, update.propertyValue));
    return newDSL;
}
//# sourceMappingURL=application.js.map