// SPDX-License-Identifier: Apache-2.0
import { IllegalArgumentError } from '../../business/errors/illegal-argument-error.js';
import { StringEx } from '../../business/utils/string-ex.js';
export class ConfigKeyFormatter {
    static _instance;
    separator = StringEx.PERIOD;
    constructor() { }
    normalize(key) {
        if (StringEx.isEmpty(key)) {
            return key;
        }
        key = key.trim();
        if (!StringEx.isUnderscored(key)) {
            // This check is necessary to properly handle environment variables and prefixes.
            // Without this check and conversion, keys and prefixes like "ENV" are converted to "eNV" which is not desired.
            if (StringEx.isUppercase(key)) {
                key = key.toLowerCase();
            }
            return StringEx.verbCase(key);
        }
        return StringEx.snakeToDotCase(key);
    }
    split(key) {
        if (!key || key.trim().length === 0) {
            throw new IllegalArgumentError('key must not be null or undefined');
        }
        return key.split(this.separator);
    }
    join(...parts) {
        if (!parts || parts.length === 0) {
            return null;
        }
        return parts.join(this.separator);
    }
    static instance() {
        if (!ConfigKeyFormatter._instance) {
            ConfigKeyFormatter._instance = new ConfigKeyFormatter();
        }
        return ConfigKeyFormatter._instance;
    }
}
//# sourceMappingURL=config-key-formatter.js.map