import { mapValues } from 'lodash';
import { ContextValue } from './ContextValue.js';
import { JinjaExpressionVariable, JinjaVariable } from './JinjaVariable.js';
export class JinjaContextValue extends ContextValue {
    constructor({ name, prefix, variables, parent }) {
        super(name);
        Object.defineProperty(this, "prefix", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "variables", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: {}
        });
        Object.defineProperty(this, "parent", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        this.parent = parent;
        this.prefix = prefix;
        if (!variables)
            return;
        Object.keys(variables).forEach((key) => {
            const { initialValue, expression, metadata } = variables[key];
            this.variables[key] = expression
                ? new JinjaExpressionVariable(key, expression, prefix)
                : new JinjaVariable(key, initialValue, prefix, metadata);
        });
    }
    findVariableByKey(key) {
        return this.variables[key];
    }
    getVariableInContext(key) {
        return this.findVariableByKey(key);
    }
    getAllInContext() {
        return mapValues(this.variables, v => v.get());
    }
    addVariablesToContext(variables) {
        for (const variable of variables) {
            this.variables[variable.name] = variable;
        }
    }
    forEachVariable(iteratee) {
        Object.values(this.variables).forEach(iteratee);
    }
}
//# sourceMappingURL=JinjaContextValue.js.map