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

/**
 * @file This module provides an API for configuring the notifications of the Launchpad shell bar.
 * It allows adding a NotificationsProvider to the notifications via for example a Plugin.
 */

sap.ui.define([
    "sap/ushell/Config",
    "sap/ushell/utils"
], (
    Config,
    ushellUtils
) => {
    "use strict";

    /**
     * @alias sap.ushell.modules.Notifications
     * @namespace
     * @description The Notifications module API to set a NotficiationsProvider and Config.
     *
     * @since 1.142.0
     * @private
     *
     * @ui5-restricted ANS
     */
    class Notifications {
        /**
         * Sets the notifications provider for the notifications module.
         * @param {string} sModulePath The module path of the notifications provider.
         * @param {object} oConfiguration  The configuration object for the notifications provider.
         *
         * @returns {Promise} A promise that resolves when the configuration is set.
         *
         * @since 1.142.0
         * @private
         * @ui5-restricted ANS
         */
        async setNotificationsProvider (sModulePath, oConfiguration) {
            Config.emit("/core/notifications", {
                enabled: true,
                modulePath: sModulePath,
                configuration: JSON.stringify(oConfiguration || {})
            });

            // ensure the NotificationsLoader is loaded so it can react to the config change.
            // This may happen asynchronously if the FLP was not configured to use notifications at startup.
            const [oNotificationsLoader] = await ushellUtils.requireAsync(["sap/ushell/modules/loader/NotificationsLoader"]);
            await oNotificationsLoader.initialized();
        }
    }
    return new Notifications();
});
