// Copyright (c) 2009-2026 SAP SE, All Rights Reserved

/**
 * @fileoverview CDM bootstrap configuration provider.
 *
 * Coordinates the initialization of BootstrapConfig, PlatformConfig, and
 * the merged UI5 configuration for the CDM platform. Returns a singleton.
 */
sap.ui.define([
    "sap/base/util/deepExtend",
    "sap/ushell/bootstrap/cdm/cdmConstants",
    "sap/ushell/bootstrap/cdm/PlatformConfig",
    "sap/ushell/bootstrap/Config"
], (
    deepExtend,
    cdmConstants,
    PlatformConfig,
    BootstrapConfig
) => {
    "use strict";

    /**
     * @alias sap.ushell.bootstrap.cdm.ConfigurationProvider
     * @namespace
     * @description Configuration provider for the CDM bootstrap.
     *
     * Initializes the ushell configuration with CDM defaults, applies
     * platform-specific settings, and merges the resulting UI5 configuration.
     *
     * @since 1.147.0
     * @private
     */
    class ConfigurationProvider {
        /** @type {object} The merged UI5 configuration */
        #oUI5Config;

        constructor () {
            this.#init();
        }

        /**
         * Initializes and merges the configuration. Applies the module paths.
         *
         * @since 1.147.0
         * @private
         */
        #init () {
            BootstrapConfig.initialize(cdmConstants.defaultConfig);

            // Extend the default config with platform specific config inplace
            PlatformConfig.configureUshell();

            this.#oUI5Config = deepExtend({}, BootstrapConfig.getUI5Config(), PlatformConfig.getUI5Config());

            BootstrapConfig.applyModulePaths();
        }

        /**
         * Returns the value of a UI5 configuration property.
         *
         * @param {string} sCamelizedKey The camelCase key of the UI5 configuration property (e.g. "sapUiTheme", "sapUiLanguage")
         * @returns {any} The value of the requested key, or <code>undefined</code>
         *
         * @since 1.147.0
         * @private
         */
        get (sCamelizedKey) {
            return this.#oUI5Config[sCamelizedKey];
        }

        /**
         * Only for testing purposes!
         * Resets the configuration and re-runs initialization.
         *
         * @since 1.147.0
         * @private
         */
        reset () {
            BootstrapConfig.reset();
            this.#init();
        }
    }

    return new ConfigurationProvider();
});
