local ____lualib = require("lualib_bundle")
local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
local ____exports = {}
local getKeysToBackup, GLOWING_HOUR_GLASS_BACKUP_KEYS, REWIND_WITH_GLOWING_HOUR_GLASS_KEY
local ____SaveDataKey = require("enums.SaveDataKey")
local SaveDataKey = ____SaveDataKey.SaveDataKey
local ____SerializationType = require("enums.SerializationType")
local SerializationType = ____SerializationType.SerializationType
local ____deepCopy = require("functions.deepCopy")
local deepCopy = ____deepCopy.deepCopy
local ____merge = require("functions.merge")
local merge = ____merge.merge
local ____table = require("functions.table")
local iterateTableInOrder = ____table.iterateTableInOrder
local ____constants = require("classes.features.other.saveDataManager.constants")
local SAVE_DATA_MANAGER_DEBUG = ____constants.SAVE_DATA_MANAGER_DEBUG
function getKeysToBackup(self, saveData)
    local shouldBackupPersistentObject = saveData.persistent ~= nil and saveData.persistent[REWIND_WITH_GLOWING_HOUR_GLASS_KEY] ~= nil
    local ____shouldBackupPersistentObject_1
    if shouldBackupPersistentObject then
        local ____array_0 = __TS__SparseArrayNew(table.unpack(GLOWING_HOUR_GLASS_BACKUP_KEYS))
        __TS__SparseArrayPush(____array_0, SaveDataKey.PERSISTENT)
        ____shouldBackupPersistentObject_1 = {__TS__SparseArraySpread(____array_0)}
    else
        ____shouldBackupPersistentObject_1 = GLOWING_HOUR_GLASS_BACKUP_KEYS
    end
    return ____shouldBackupPersistentObject_1
end
GLOWING_HOUR_GLASS_BACKUP_KEYS = {SaveDataKey.RUN, SaveDataKey.LEVEL}
local IGNORE_GLOWING_HOUR_GLASS_KEY = "__ignoreGlowingHourGlass"
REWIND_WITH_GLOWING_HOUR_GLASS_KEY = "__rewindWithGlowingHourGlass"
function ____exports.makeGlowingHourGlassBackup(self, saveDataMap, saveDataConditionalFuncMap, saveDataGlowingHourGlassMap)
    iterateTableInOrder(
        nil,
        saveDataMap,
        function(____, subscriberName, saveData)
            local conditionalFunc = saveDataConditionalFuncMap[subscriberName]
            if conditionalFunc ~= nil then
                local shouldSave = conditionalFunc(nil)
                if not shouldSave then
                    return
                end
            end
            for ____, saveDataKey in ipairs(getKeysToBackup(nil, saveData)) do
                do
                    local childTable = saveData[saveDataKey]
                    if childTable == nil then
                        goto __continue6
                    end
                    local childTableLuaMap = childTable
                    if childTableLuaMap[IGNORE_GLOWING_HOUR_GLASS_KEY] ~= nil then
                        goto __continue6
                    end
                    local saveDataGlowingHourGlass = saveDataGlowingHourGlassMap[subscriberName]
                    if saveDataGlowingHourGlass == nil then
                        saveDataGlowingHourGlass = {}
                        saveDataGlowingHourGlassMap[subscriberName] = saveDataGlowingHourGlass
                    end
                    local copiedChildTable = deepCopy(nil, childTable, SerializationType.SERIALIZE)
                    saveDataGlowingHourGlass[saveDataKey] = copiedChildTable
                end
                ::__continue6::
            end
        end,
        SAVE_DATA_MANAGER_DEBUG
    )
end
function ____exports.restoreGlowingHourGlassBackup(self, saveDataMap, saveDataConditionalFuncMap, saveDataGlowingHourGlassMap, classConstructors)
    iterateTableInOrder(
        nil,
        saveDataMap,
        function(____, subscriberName, saveData)
            local conditionalFunc = saveDataConditionalFuncMap[subscriberName]
            if conditionalFunc ~= nil then
                local shouldSave = conditionalFunc(nil)
                if not shouldSave then
                    return
                end
            end
            for ____, saveDataKey in ipairs(getKeysToBackup(nil, saveData)) do
                do
                    local childTable = saveData[saveDataKey]
                    if childTable == nil then
                        goto __continue15
                    end
                    local childTableLuaMap = childTable
                    if childTableLuaMap[IGNORE_GLOWING_HOUR_GLASS_KEY] ~= nil then
                        goto __continue15
                    end
                    local saveDataGlowingHourGlass = saveDataGlowingHourGlassMap[subscriberName]
                    if saveDataGlowingHourGlass == nil then
                        goto __continue15
                    end
                    local childTableBackup = saveDataGlowingHourGlass[saveDataKey]
                    if childTableBackup == nil then
                        goto __continue15
                    end
                    merge(
                        nil,
                        childTable,
                        childTableBackup,
                        subscriberName .. "__glowingHourGlass",
                        classConstructors
                    )
                end
                ::__continue15::
            end
        end,
        SAVE_DATA_MANAGER_DEBUG
    )
end
return ____exports
