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

sap.ui.define([
    "sap/ui/model/odata/v2/ODataModel"
], (
    ODataModel
) => {
    "use strict";

    const FakeModel = new Proxy(ODataModel, {
        construct: function (Target, aArgs) {
            const oModel = new Target(...aArgs);
            const oModelProxy = new Proxy(oModel, {
                get: function (oTarget, sProperty) {
                    if (sProperty === "setDeferredGroups") {
                        return function () {
                            ODataModel.prototype.setDeferredGroups.apply(oTarget, arguments);
                            oTarget.mDeferredGroups.undefined = "undefined";
                        };
                    }
                    return oTarget[sProperty];
                }
            });

            // set default group as deferred to suppress requests
            oModelProxy.setDeferredGroups(["undefined", oModel.sDefaultChangeGroup]);

            return oModelProxy;
        }
    });

    return FakeModel;
});
