/**
 * Deep-clone a template object and replace every exact "$value" string
 * with the provided value. Only exact matches are replaced — "$value"
 * embedded in a larger string (e.g. "prefix-$value") is left as-is.
 */
export function substituteValue(template, value) {
    const cloned = JSON.parse(JSON.stringify(template));
    function walk(obj) {
        if (typeof obj === "string" && obj === "$value")
            return value;
        if (Array.isArray(obj))
            return obj.map(walk);
        if (obj !== null && typeof obj === "object") {
            const record = obj;
            for (const key of Object.keys(record)) {
                record[key] = walk(record[key]);
            }
        }
        return obj;
    }
    walk(cloned);
    return cloned;
}
/**
 * Apply declarative expansion rules to an input map.
 * For each rule whose triggerKey is present (and skipIfPresent guard is not),
 * merge the expanded structure into the result.
 *
 * Rules are applied in order. The original input is not mutated.
 */
export function applyInputExpansions(inputs, rules) {
    let result = { ...inputs };
    for (const rule of rules) {
        const value = result[rule.triggerKey];
        if (value === undefined)
            continue;
        if (rule.skipIfPresent && result[rule.skipIfPresent] !== undefined)
            continue;
        const expanded = substituteValue(rule.expand, value);
        result = { ...result, ...expanded };
    }
    return result;
}
//# sourceMappingURL=input-expander.js.map