"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.objectUtils = void 0;
exports.getNestedValue = getNestedValue;
exports.unflattenObject = unflattenObject;
exports.flattenObject = flattenObject;
exports.parseByMimeType = parseByMimeType;
function getNestedValue(obj, path, separator = '.') {
    if (!obj || typeof obj !== 'object') {
        return undefined;
    }
    const keys = Array.isArray(path)
        ? path.flatMap((k) => k.split(separator))
        : path.split(separator);
    return keys.reduce((acc, key) => acc === null || acc === void 0 ? void 0 : acc[key], obj);
}
function unflattenObject(flat) {
    const result = {};
    for (const [key, value] of Object.entries(flat)) {
        const parts = key.split('.');
        let current = result;
        for (let i = 0; i < parts.length - 1; i++) {
            current[parts[i]] = current[parts[i]] || {};
            current = current[parts[i]];
        }
        current[parts[parts.length - 1]] = value;
    }
    return result;
}
function flattenObject(obj, prefix = '') {
    const result = {};
    for (const [key, value] of Object.entries(obj)) {
        const newKey = prefix ? `${prefix}.${key}` : key;
        if (value && typeof value === 'object' && !Array.isArray(value)) {
            Object.assign(result, flattenObject(value, newKey));
        }
        else {
            result[newKey] = value;
        }
    }
    return result;
}
function parseByMimeType(value, mime_type) {
    try {
        switch (mime_type) {
            case 'application/json':
                const jsonData = JSON.parse(value);
                return jsonData;
            default:
                return value;
        }
    }
    catch (error) {
        return value;
    }
}
exports.objectUtils = {
    getNestedValue,
    flattenObject,
    unflattenObject,
    parseByMimeType,
};
exports.default = exports.objectUtils;
