local ____lualib = require("lualib_bundle")
local Set = ____lualib.Set
local __TS__New = ____lualib.__TS__New
local __TS__ArraySome = ____lualib.__TS__ArraySome
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local ItemConfigCardType = ____isaac_2Dtypescript_2Ddefinitions.ItemConfigCardType
local UseFlag = ____isaac_2Dtypescript_2Ddefinitions.UseFlag
local ____cachedEnumValues = require("arrays.cachedEnumValues")
local POCKET_ITEM_SLOT_VALUES = ____cachedEnumValues.POCKET_ITEM_SLOT_VALUES
local ____cachedClasses = require("core.cachedClasses")
local itemConfig = ____cachedClasses.itemConfig
local ____constantsFirstLast = require("core.constantsFirstLast")
local LAST_VANILLA_CARD_TYPE = ____constantsFirstLast.LAST_VANILLA_CARD_TYPE
local ____cardDescriptions = require("objects.cardDescriptions")
local CARD_DESCRIPTIONS = ____cardDescriptions.CARD_DESCRIPTIONS
local DEFAULT_CARD_DESCRIPTION = ____cardDescriptions.DEFAULT_CARD_DESCRIPTION
local ____cardNames = require("objects.cardNames")
local CARD_NAMES = ____cardNames.CARD_NAMES
local DEFAULT_CARD_NAME = ____cardNames.DEFAULT_CARD_NAME
local ____itemConfigCardTypesForCards = require("sets.itemConfigCardTypesForCards")
local ITEM_CONFIG_CARD_TYPES_FOR_CARDS = ____itemConfigCardTypesForCards.ITEM_CONFIG_CARD_TYPES_FOR_CARDS
local ____flag = require("functions.flag")
local addFlag = ____flag.addFlag
local ____types = require("functions.types")
local asCardType = ____types.asCardType
function ____exports.isVanillaCardType(self, cardType)
    return cardType <= LAST_VANILLA_CARD_TYPE
end
--- Helper function to get a card description from a `CardType` value. Returns "Unknown" if the
-- provided card type is not valid.
-- 
-- This function works for both vanilla and modded trinkets.
-- 
-- For example, `getCardDescription(CardType.FOOL)` would return "Where journey begins".
function ____exports.getCardDescription(self, cardType)
    local cardDescription = CARD_DESCRIPTIONS[cardType]
    if cardDescription ~= nil then
        return cardDescription
    end
    local itemConfigCard = itemConfig:GetCard(cardType)
    if itemConfigCard ~= nil then
        return itemConfigCard.Description
    end
    return DEFAULT_CARD_DESCRIPTION
end
--- Helper function to get the name of a card. Returns "Unknown" if the provided card type is not
-- valid.
-- 
-- This function works for both vanilla and modded trinkets.
-- 
-- For example, `getCardName(Card.FOOL)` would return "0 - The Fool".
function ____exports.getCardName(self, cardType)
    local cardName = CARD_NAMES[cardType]
    if cardName ~= nil then
        return cardName
    end
    local itemConfigCard = itemConfig:GetCard(cardType)
    if itemConfigCard ~= nil then
        return itemConfigCard.Name
    end
    return DEFAULT_CARD_NAME
end
--- Helper function to get the item config card type of a particular card, rune, or object. For
-- example, the item config card type of `CardType.FOOL` is equal to `ItemConfigCardType.TAROT`.
-- 
-- Returns undefined if the provided card type was not valid.
function ____exports.getItemConfigCardType(self, cardType)
    local itemConfigCard = itemConfig:GetCard(cardType)
    if itemConfigCard == nil then
        return nil
    end
    return itemConfigCard.CardType
end
--- Helper function to check if a player is holding a specific card in one of their pocket item
-- slots.
-- 
-- This function is variadic, meaning that you can pass as many cards as you want to check for. The
-- function will return true if the player has any of the cards.
function ____exports.hasCard(self, player, ...)
    local cardTypes = {...}
    local cardTypesSet = __TS__New(Set, cardTypes)
    return __TS__ArraySome(
        POCKET_ITEM_SLOT_VALUES,
        function(____, pocketItemSlot)
            local cardType = player:GetCard(pocketItemSlot)
            return cardTypesSet:has(cardType)
        end
    )
end
--- Returns true for card types that have the following item config card type:
-- 
-- - `ItemConfigCardType.TAROT` (0)
-- - `ItemConfigCardType.SUIT` (1)
-- - `ItemConfigCardType.SPECIAL` (3)
-- - `ItemConfigCardType.TAROT_REVERSE` (5)
function ____exports.isCard(self, cardType)
    local itemConfigCardType = ____exports.getItemConfigCardType(nil, cardType)
    if itemConfigCardType == nil then
        return false
    end
    return ITEM_CONFIG_CARD_TYPES_FOR_CARDS:has(itemConfigCardType)
end
--- Returns whether the given card type matches the specified item config card type.
function ____exports.isCardType(self, cardType, itemConfigCardType)
    return itemConfigCardType == ____exports.getItemConfigCardType(nil, cardType)
end
--- Returns true for any card type added by a mod.
function ____exports.isModdedCardType(self, cardType)
    return not ____exports.isVanillaCardType(nil, cardType)
end
--- Returns true for card types that have `ItemConfigCardType.SPECIAL_OBJECT`.
function ____exports.isPocketItemObject(self, cardType)
    return ____exports.isCardType(nil, cardType, ItemConfigCardType.SPECIAL_OBJECT)
end
--- Returns true for card types that have `ItemConfigCardType.TAROT_REVERSE`.
function ____exports.isReverseTarotCard(self, cardType)
    return ____exports.isCardType(nil, cardType, ItemConfigCardType.TAROT_REVERSE)
end
--- Returns true for card types that have `ItemConfigCardType.RUNE`.
function ____exports.isRune(self, cardType)
    return ____exports.isCardType(nil, cardType, ItemConfigCardType.RUNE)
end
--- Returns true for card types that have `ItemConfigCardType.SPECIAL`.
function ____exports.isSpecialCard(self, cardType)
    return ____exports.isCardType(nil, cardType, ItemConfigCardType.SPECIAL)
end
--- Returns true for card types that have `ItemConfigCardType.SUIT`.
function ____exports.isSuitCard(self, cardType)
    return ____exports.isCardType(nil, cardType, ItemConfigCardType.SUIT)
end
--- Returns true for card types that have `ItemConfigCardType.TAROT`.
function ____exports.isTarotCard(self, cardType)
    return ____exports.isCardType(nil, cardType, ItemConfigCardType.TAROT)
end
function ____exports.isValidCardType(self, cardType)
    local potentialCardType = asCardType(nil, cardType)
    local itemConfigCard = itemConfig:GetCard(potentialCardType)
    return itemConfigCard ~= nil
end
--- Helper function to use a card without showing an animation and without the announcer voice
-- playing.
function ____exports.useCardTemp(self, player, cardType)
    local useFlags = addFlag(nil, UseFlag.NO_ANIMATION, UseFlag.NO_ANNOUNCER_VOICE)
    player:UseCard(cardType, useFlags)
end
return ____exports
