local ____lualib = require("lualib_bundle")
local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local DamageFlag = ____isaac_2Dtypescript_2Ddefinitions.DamageFlag
--- Helper function to add a bit flag to an existing set of bit flags.
-- 
-- This is a variadic function, so pass as many flags as you want to add.
-- 
-- Example 1:
-- 
-- ```ts
-- // Give the player spectral tears
-- const player = Isaac.GetPlayer();
-- player.TearFlags = addFlag(player.TearFlags, TearFlags.TEAR_SPECTRAL);
-- ```
-- 
-- Example 2:
-- 
-- ```ts
-- // Give the player spectral and homing tears
-- const player = Isaac.GetPlayer();
-- player.TearFlags = addFlag(player.TearFlags, TearFlags.TEAR_SPECTRAL, TearFlags.TEAR_HOMING);
-- ```
-- 
-- @param flags The existing set of bit flags.
-- @param flagsToAdd One or more bit flags to add, each as a separate argument.
-- @returns The combined bit flags.
function ____exports.addFlag(self, flags, ...)
    local flagsToAdd = {...}
    local flagsAsInt = flags
    for ____, flagToAdd in ipairs(flagsToAdd) do
        flagsAsInt = flagsAsInt | flagToAdd
    end
    return flagsAsInt
end
--- Helper function for casting a flag enum value to a `BitFlags` object.
-- 
-- This is useful because the compiler will prevent you from assigning a specific flag to a
-- `BitFlags` field. (It does this to ensure type safety, since `BitFlags` can represent a zero
-- value or a composition of N flags.)
-- 
-- For example:
-- 
-- ```ts
-- player.TearFlags = bitFlags(TearFlag.SPECTRAL);
-- ```
function ____exports.bitFlags(self, flag)
    return flag
end
--- Helper function to get the key associated with a particular flag.
-- 
-- (Since bit flags are represented by custom objects instead of normal TypeScript enums, you cannot
-- use the reverse mapping to find the associated key of a given enum value. Use this helper
-- function instead of indexing the enum directly.)
function ____exports.getFlagName(self, flag, flagEnum)
    for ____, ____value in ipairs(__TS__ObjectEntries(flagEnum)) do
        local key = ____value[1]
        local value = ____value[2]
        if value == flag then
            return key
        end
    end
    return nil
end
--- Helper function to determine if a particular bit flag is set to true.
-- 
-- This is a variadic function, so pass as many flags as you want to check for. If passed multiple
-- flags, it will only return true if all of the flags are set.
-- 
-- For example:
-- 
-- ```ts
-- const player = Isaac.GetPlayer();
-- if (hasFlag(player.TearFlags, TearFlags.TEAR_SPECTRAL) {
--   // The player currently has spectral tears
-- }
-- ```
-- 
-- @param flags The existing set of bit flags.
-- @param flagsToCheck One or more bit flags to check for, each as a separate argument.
function ____exports.hasFlag(self, flags, ...)
    local flagsToCheck = {...}
    local flagsAsInt = flags
    for ____, flagToCheck in ipairs(flagsToCheck) do
        if not (flagsAsInt & flagToCheck == flagToCheck) then
            return false
        end
    end
    return true
end
--- Helper function to check if every bit in the flag is turned off.
-- 
-- (This is equivalent to checking if the flag is equal to 0, but this is not possible without
-- casting the flag to a number.)
function ____exports.isEmptyFlag(self, flag)
    return flag == 0
end
--- Helper function to determine whether damage to a player in the `ENTITY_TAKE_DMG` callback was
-- self-inflicted. For example, damage from a Curse Room door, a Razor, or a Blood Donation Machine
-- would count as self-inflicted damage.
function ____exports.isSelfDamage(self, damageFlags)
    return ____exports.hasFlag(nil, damageFlags, DamageFlag.NO_PENALTIES) or ____exports.hasFlag(nil, damageFlags, DamageFlag.RED_HEARTS)
end
--- Helper function to remove a bit flag from an existing set of bit flags.
-- 
-- This is a variadic function, so pass as many flags as you want to remove.
-- 
-- For example:
-- 
-- ```ts
-- // Remove spectral tears from the player, if present
-- const player = Isaac.GetPlayer();
-- player.TearFlags = removeFlag(player.TearFlags, TearFlags.TEAR_SPECTRAL);
-- ```
-- 
-- @param flags The existing set of bit flags.
-- @param flagsToRemove One or more bit flags to remove, each as a separate argument.
-- @returns The combined bit flags.
function ____exports.removeFlag(self, flags, ...)
    local flagsToRemove = {...}
    local flagsAsInt = flags
    for ____, flagToRemove in ipairs(flagsToRemove) do
        flagsAsInt = flagsAsInt & ~flagToRemove
    end
    return flagsAsInt
end
return ____exports
