local ____lualib = require("lualib_bundle")
local Map = ____lualib.Map
local __TS__New = ____lualib.__TS__New
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__DecorateLegacy = ____lualib.__TS__DecorateLegacy
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
local ____decorators = require("decorators")
local Exported = ____decorators.Exported
local ____ModCallbackCustom = require("enums.ModCallbackCustom")
local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
local ____array = require("functions.array")
local arrayRemoveIndexInPlace = ____array.arrayRemoveIndexInPlace
local ____map = require("functions.map")
local copyMap = ____map.copyMap
local ____utils = require("functions.utils")
local assertDefined = ____utils.assertDefined
local ____weighted = require("functions.weighted")
local getRandomIndexFromWeightedArray = ____weighted.getRandomIndexFromWeightedArray
local ____Feature = require("classes.private.Feature")
local Feature = ____Feature.Feature
local v = {run = {customItemPools = __TS__New(Map)}}
local customItemPoolMap = __TS__New(Map)
____exports.CustomItemPools = __TS__Class()
local CustomItemPools = ____exports.CustomItemPools
CustomItemPools.name = "CustomItemPools"
__TS__ClassExtends(CustomItemPools, Feature)
function CustomItemPools.prototype.____constructor(self)
    Feature.prototype.____constructor(self)
    self.v = v
    self.postGameStartedReorderedFalse = function()
        v.run.customItemPools = copyMap(nil, customItemPoolMap)
    end
    self.customCallbacksUsed = {{ModCallbackCustom.POST_GAME_STARTED_REORDERED, self.postGameStartedReorderedFalse, {false}}}
end
function CustomItemPools.prototype.registerCustomItemPool(self, itemPoolTypeCustom, collectibles)
    if customItemPoolMap:has(itemPoolTypeCustom) then
        error(("Failed to register a custom item pool since the provided type of " .. tostring(itemPoolTypeCustom)) .. " was already registered.")
    end
    customItemPoolMap:set(itemPoolTypeCustom, collectibles)
end
__TS__DecorateLegacy({Exported}, CustomItemPools.prototype, "registerCustomItemPool", true)
function CustomItemPools.prototype.getCustomItemPoolCollectible(self, itemPoolTypeCustom, seedOrRNG, decrease, defaultItem)
    if decrease == nil then
        decrease = false
    end
    if defaultItem == nil then
        defaultItem = CollectibleType.NULL
    end
    local customItemPool = v.run.customItemPools:get(itemPoolTypeCustom)
    assertDefined(
        nil,
        customItemPool,
        "Failed to find the custom item pool of: " .. tostring(itemPoolTypeCustom)
    )
    if #customItemPool == 0 then
        return defaultItem
    end
    local randomIndex = getRandomIndexFromWeightedArray(nil, customItemPool, seedOrRNG)
    local tuple = customItemPool[randomIndex + 1]
    assertDefined(
        nil,
        tuple,
        "Failed to get an element from a custom item pool using a random index of: " .. tostring(randomIndex)
    )
    if decrease then
        arrayRemoveIndexInPlace(nil, customItemPool, randomIndex)
    end
    return tuple[1]
end
__TS__DecorateLegacy({Exported}, CustomItemPools.prototype, "getCustomItemPoolCollectible", true)
return ____exports
