local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
local Map = ____lualib.Map
local __TS__New = ____lualib.__TS__New
local __TS__DecorateLegacy = ____lualib.__TS__DecorateLegacy
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local CacheFlag = ____isaac_2Dtypescript_2Ddefinitions.CacheFlag
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
local LevelCurse = ____isaac_2Dtypescript_2Ddefinitions.LevelCurse
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local TearVariant = ____isaac_2Dtypescript_2Ddefinitions.TearVariant
local ____decorators = require("decorators")
local Exported = ____decorators.Exported
local ____ModCallbackCustom = require("enums.ModCallbackCustom")
local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
local ____console = require("functions.console")
local isVanillaConsoleCommand = ____console.isVanillaConsoleCommand
local ____flag = require("functions.flag")
local addFlag = ____flag.addFlag
local bitFlags = ____flag.bitFlags
local ____log = require("functions.log")
local logError = ____log.logError
local ____string = require("functions.string")
local getMapPartialMatch = ____string.getMapPartialMatch
local ____utils = require("functions.utils")
local assertDefined = ____utils.assertDefined
local ____Feature = require("classes.private.Feature")
local Feature = ____Feature.Feature
local commands = require("classes.features.other.extraConsoleCommands.commands")
local ____v = require("classes.features.other.extraConsoleCommands.v")
local v = ____v.v
--- When you enable this feature, many custom commands will be added to the in-game console. See the
-- [dedicated command list](ExtraConsoleCommandsList) for more information about them.
-- 
-- Note that in order to avoid conflicts, if two or more mods enable this feature, then the first
-- loaded one will control all of the command logic. When this occurs, a global variable of
-- `__ISAACSCRIPT_COMMON_EXTRA_CONSOLE_COMMANDS_FEATURE` will be created and will automatically be
-- used by the non-main instances. For this reason, if you use multiple mods with
-- `isaacscript-common` and a custom command from the standard library is not working properly, then
-- you might need to get another mod author to update their version of `isaacscript-common`.
____exports.ExtraConsoleCommands = __TS__Class()
local ExtraConsoleCommands = ____exports.ExtraConsoleCommands
ExtraConsoleCommands.name = "ExtraConsoleCommands"
__TS__ClassExtends(ExtraConsoleCommands, Feature)
function ExtraConsoleCommands.prototype.____constructor(self)
    Feature.prototype.____constructor(self)
    self.v = v
    self.commandFunctionMap = __TS__New(Map)
    self.postUpdate = function()
        if v.persistent.spamBloodRights then
            local player = Isaac.GetPlayer()
            player:UseActiveItem(CollectibleType.BLOOD_RIGHTS)
        end
    end
    self.evaluateCacheDamage = function(____, player)
        if v.persistent.damage then
            player.Damage = v.persistent.damageAmount
        end
    end
    self.evaluateCacheFireDelay = function(____, player)
        if v.persistent.tears then
            player.FireDelay = v.persistent.tearsAmount
        end
    end
    self.evaluateCacheSpeed = function(____, player)
        if v.persistent.speed then
            player.MoveSpeed = v.persistent.speedAmount
        end
    end
    self.evaluateCacheFlying = function(____, player)
        if v.persistent.flight then
            player.CanFly = true
        end
    end
    self.postCurseEval = function(____, curses)
        if v.persistent.disableCurses then
            return bitFlags(nil, LevelCurse.NONE)
        end
        local newCurses = curses
        if v.persistent.darkness then
            newCurses = addFlag(nil, newCurses, LevelCurse.DARKNESS)
        end
        if v.persistent.labyrinth then
            newCurses = addFlag(nil, newCurses, LevelCurse.LABYRINTH)
        end
        if v.persistent.lost then
            newCurses = addFlag(nil, newCurses, LevelCurse.LOST)
        end
        if v.persistent.unknown then
            newCurses = addFlag(nil, newCurses, LevelCurse.UNKNOWN)
        end
        if v.persistent.cursed then
            newCurses = addFlag(nil, newCurses, LevelCurse.CURSED)
        end
        if v.persistent.maze then
            newCurses = addFlag(nil, newCurses, LevelCurse.MAZE)
        end
        if v.persistent.blind then
            newCurses = addFlag(nil, newCurses, LevelCurse.BLIND)
        end
        if v.persistent.giant then
            newCurses = addFlag(nil, newCurses, LevelCurse.GIANT)
        end
        local ____temp_0
        if curses == newCurses then
            ____temp_0 = nil
        else
            ____temp_0 = newCurses
        end
        return ____temp_0
    end
    self.executeCmd = function(____, command, params)
        local resultTuple = getMapPartialMatch(nil, command, self.commandFunctionMap)
        if resultTuple == nil then
            return
        end
        local commandName, commandFunction = table.unpack(resultTuple)
        print("Command: " .. commandName)
        commandFunction(nil, params)
    end
    self.postFireTear = function(____, tear)
        if v.persistent.chaosCardTears then
            tear:ChangeVariant(TearVariant.CHAOS_CARD)
        end
    end
    self.entityTakeDmgPlayer = function(____, _player, _damageAmount, _damageFlags, _damageSource, _damageCountdownFrames)
        if v.persistent.spamBloodRights then
            return false
        end
        return nil
    end
    self.isMainFeature = __ISAACSCRIPT_COMMON_EXTRA_CONSOLE_COMMANDS_FEATURE == nil
    if not self.isMainFeature then
        return
    end
    __ISAACSCRIPT_COMMON_EXTRA_CONSOLE_COMMANDS_FEATURE = self
    self.callbacksUsed = {
        {ModCallback.POST_UPDATE, self.postUpdate},
        {ModCallback.EVALUATE_CACHE, self.evaluateCacheDamage, {CacheFlag.DAMAGE}},
        {ModCallback.EVALUATE_CACHE, self.evaluateCacheFireDelay, {CacheFlag.FIRE_DELAY}},
        {ModCallback.EVALUATE_CACHE, self.evaluateCacheSpeed, {CacheFlag.SPEED}},
        {ModCallback.EVALUATE_CACHE, self.evaluateCacheFlying, {CacheFlag.FLYING}},
        {ModCallback.POST_CURSE_EVAL, self.postCurseEval},
        {ModCallback.EXECUTE_CMD, self.executeCmd},
        {ModCallback.POST_FIRE_TEAR, self.postFireTear}
    }
    self.customCallbacksUsed = {{ModCallbackCustom.ENTITY_TAKE_DMG_PLAYER, self.entityTakeDmgPlayer}}
    for ____, ____value in ipairs(__TS__ObjectEntries(commands)) do
        local funcName = ____value[1]
        local func = ____value[2]
        self.commandFunctionMap:set(funcName, func)
    end
end
function ExtraConsoleCommands.prototype.addConsoleCommand(self, commandName, commandFunction)
    if not self.isMainFeature then
        assertDefined(nil, __ISAACSCRIPT_COMMON_EXTRA_CONSOLE_COMMANDS_FEATURE, "Failed to find the non-main isaacscript-common extra console commands feature in the global variable.")
        __ISAACSCRIPT_COMMON_EXTRA_CONSOLE_COMMANDS_FEATURE:addConsoleCommand(commandName, commandFunction)
        return
    end
    if isVanillaConsoleCommand(nil, commandName) then
        logError(("Failed to add a new console command of \"" .. commandName) .. "\" because that name already belongs to a vanilla command. You must pick a non-colliding name.")
        return
    end
    if self.commandFunctionMap:has(commandName) then
        logError(("Failed to add a new console command of \"" .. commandName) .. "\" because there is already an existing custom command by that name. If you want to overwrite a command from the standard library, you can use the \"removeExtraConsoleCommand\" function.")
        return
    end
    self.commandFunctionMap:set(commandName, commandFunction)
end
__TS__DecorateLegacy({Exported}, ExtraConsoleCommands.prototype, "addConsoleCommand", true)
function ExtraConsoleCommands.prototype.removeConsoleCommand(self, commandName)
    if not self.isMainFeature then
        assertDefined(nil, __ISAACSCRIPT_COMMON_EXTRA_CONSOLE_COMMANDS_FEATURE, "Failed to find the non-main isaacscript-common extra console commands feature in the global variable.")
        __ISAACSCRIPT_COMMON_EXTRA_CONSOLE_COMMANDS_FEATURE:removeConsoleCommand(commandName)
        return
    end
    if not self.commandFunctionMap:has(commandName) then
        error(("Failed to remove the console command of \"" .. commandName) .. "\", since it does not already exist in the command map.")
    end
    self.commandFunctionMap:delete(commandName)
end
__TS__DecorateLegacy({Exported}, ExtraConsoleCommands.prototype, "removeConsoleCommand", true)
function ExtraConsoleCommands.prototype.removeAllConsoleCommands(self)
    self.commandFunctionMap:clear()
end
__TS__DecorateLegacy({Exported}, ExtraConsoleCommands.prototype, "removeAllConsoleCommands", true)
return ____exports
