local ____lualib = require("lualib_bundle")
local __TS__Iterator = ____lualib.__TS__Iterator
local Set = ____lualib.Set
local __TS__New = ____lualib.__TS__New
local ____exports = {}
local initOptionalFeatures
local ____ModUpgraded = require("classes.ModUpgraded")
local ModUpgraded = ____ModUpgraded.ModUpgraded
local ____patchErrorFunctions = require("patchErrorFunctions")
local patchErrorFunction = ____patchErrorFunctions.patchErrorFunction
local ____shaderCrashFix = require("shaderCrashFix")
local applyShaderCrashFix = ____shaderCrashFix.applyShaderCrashFix
function initOptionalFeatures(self, mod, features)
    for ____, feature in ipairs(features) do
        local exportedMethodTuples = mod.initOptionalFeature(mod, feature)
        local modRecord = mod
        for ____, ____value in ipairs(exportedMethodTuples) do
            local funcName = ____value[1]
            local func = ____value[2]
            if modRecord[funcName] ~= nil then
                error(("Failed to upgrade the mod since two or more features share the name function name of \"" .. funcName) .. "\". This should never happen, so report this error to the library authors.")
            end
            modRecord[funcName] = func
        end
    end
end
--- Use this function to enable the custom callbacks and other optional features provided by
-- `isaacscript-common`.
-- 
-- For example:
-- 
-- ```ts
-- const modVanilla = RegisterMod("My Mod", 1);
-- const mod = upgradeMod(modVanilla);
-- 
-- // Subscribe to vanilla callbacks.
-- mod.AddCallback(ModCallback.POST_UPDATE, postUpdate);
-- 
-- // Subscribe to custom callbacks.
-- mod.AddCallbackCustom(ModCallbackCustom.POST_ITEM_PICKUP, postItemPickup);
-- ```
-- 
-- @param modVanilla The mod object returned by the `RegisterMod` function.
-- @param features Optional. An array containing the optional standard library features that you
-- want to enable, if any. Default is an empty array.
-- @param debug Optional. Whether to log additional output when a callback is fired. Default is
-- false.
-- @param timeThreshold Optional. If provided, will only log callbacks that take longer than the
-- specified number of seconds (if the "--luadebug" launch flag is turned on)
-- or milliseconds (if the "--luadebug" launch flag is turned off).
-- @returns The upgraded mod object.
function ____exports.upgradeMod(self, modVanilla, features, ____debug, timeThreshold)
    if features == nil then
        features = {}
    end
    if ____debug == nil then
        ____debug = false
    end
    for ____, feature in __TS__Iterator(features) do
        local featureType = type(feature)
        if featureType ~= "number" then
            error(("Failed to upgrade the mod due to one of the specified features being of type \"" .. featureType) .. "\". (All of the features should be numbers represented by the \"ISCFeature\" enum.)")
        end
    end
    local featureSet = __TS__New(Set, features)
    if featureSet.size ~= #features then
        error("Failed to upgrade the mod since there are two or more of the same features specified in the \"features\" array. When you pass the array of features to the \"upgradeMod\" function, all of the elements should be unique.")
    end
    patchErrorFunction(nil)
    local mod = __TS__New(ModUpgraded, modVanilla, ____debug, timeThreshold)
    applyShaderCrashFix(nil, mod)
    initOptionalFeatures(nil, mod, features)
    return mod
end
return ____exports
