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

/**
 * @fileOverview The app runtime wrapper for {@link sap.ushell.services.AppLifeCycle}.
 *
 * @version 1.148.1
 */
sap.ui.define([
    "sap/base/Log",
    "sap/ushell/appRuntime/ui5/AppCommunicationMgr",
    "sap/ushell/services/AppLifeCycle",
    "sap/ushell/appRuntime/ui5/services/AppLifeCycleAgent"
], (
    Log,
    AppCommunicationMgr,
    AppLifeCycle,
    AppLifeCycleAgent
) => {
    "use strict";

    /**
     * @alias sap.ushell.appRuntime.ui5.services.AppLifeCycle
     * @class
     * @classdesc The app runtime wrapper for {@link sap.ushell.services.AppLifeCycle}.
     *
     * @hideconstructor
     *
     * @param {object} oContainerInterface not used
     * @param {string} sParameters not used
     * @param {object} oServiceConfiguration not used
     *
     * @since 1.127.0
     * @private
     */
    function AppLifeCycleProxy (oContainerInterface, sParameters, oServiceConfiguration) {
        AppLifeCycle.call(this, oContainerInterface, sParameters, oServiceConfiguration);

        /**
         * Reloads the currently displayed app (used by RTA plugin).
         *
         * @since 1.127.0
         * @private
         */
        this.reloadCurrentApp = async function () {
            try {
                await AppCommunicationMgr.postMessageToFLP("sap.ushell.services.AppLifeCycle.reloadCurrentApp", {});
            } catch (oError) {
                Log.error("reloadCurrentApp failed: ", oError);
            }
        };

        /**
         * Use legacy restore flow for current application.
         *
         * @param {string} sComponentId The component id of the application
         * @param {boolean} bDisableRouterRetrigger
         *     A flag to disable or enable the router's re-trigger
         *     when a keep-alive application is restored
         *
         * @since 1.141.0
         * @private
         */
        this.useLegacyRestoreFlowForCurrentApplication = async function (sComponentId, bDisableRouterRetrigger) {
            AppLifeCycleAgent.useLegacyRestoreFlowForCurrentApplication(sComponentId, bDisableRouterRetrigger);
        };
    }

    AppLifeCycleProxy.prototype = AppLifeCycle.prototype;
    AppLifeCycleProxy.hasNoAdapter = AppLifeCycle.hasNoAdapter;

    return AppLifeCycleProxy;
});
