import { CONFIG_SCHEMA } from '../config/index.js';
function setNestedValue(target, path, value) {
    let current = target;
    for (let index = 0; index < path.length - 1; index += 1) {
        const segment = path[index];
        const existing = current[segment];
        if (!existing || typeof existing !== 'object') {
            current[segment] = {};
        }
        current = current[segment];
    }
    current[path[path.length - 1]] = structuredClone(value);
}
function getNestedValue(source, path) {
    let current = source;
    for (const segment of path) {
        if (!current || typeof current !== 'object')
            return undefined;
        current = current[segment];
    }
    return current;
}
export function configSnapshotToProfileData(snapshot) {
    const profile = {};
    for (const entry of CONFIG_SCHEMA) {
        if (!entry.key.startsWith('display.')
            && !entry.key.startsWith('provider.')
            && !entry.key.startsWith('behavior.')) {
            continue;
        }
        const value = snapshot[entry.key];
        if (value !== undefined) {
            setNestedValue(profile, entry.key.split('.'), value);
        }
    }
    return profile;
}
export function profileDataToConfigSnapshot(data) {
    const snapshot = {};
    for (const entry of CONFIG_SCHEMA) {
        if (!entry.key.startsWith('display.')
            && !entry.key.startsWith('provider.')
            && !entry.key.startsWith('behavior.')) {
            continue;
        }
        const value = getNestedValue(data, entry.key.split('.'));
        if (value !== undefined)
            snapshot[entry.key] = structuredClone(value);
    }
    return snapshot;
}
