-- WalletFix.lua
-- Fixes Wallet Fixes for Inventory Tetris B42

local Logger = require("Utils/Logger")
local WalletFix = {}

function WalletFix.apply()
    -- Load compatibility module
    local success, TetrisModCompatibility = pcall(require, "InventoryTetris/TetrisModCompatibility")
    if not success or not TetrisModCompatibility then
        Logger.error("TetrisModCompatibility not available - is Inventory Tetris loaded?")
        return false
    end

    Logger.log("Applying WalletFix patches...")

    -- Save original function
    local original_getModContainerKey = TetrisModCompatibility.getModContainerKey

    -- Corrected patched function
    function TetrisModCompatibility.getModContainerKey(container)
        if not container then
            return nil
        end

        -- Knox Event Expanded NPC inventories
        if container:getParent() and instanceof(container:getParent(), "IsoNpcPlayer") then
            return "npcKEE"
        end

        -- ⭐ IMPORTANT: normal containers MUST return the original key
        return original_getModContainerKey(container)
    end

    Logger.success("WalletFix patches applied successfully")
    return true
end

return WalletFix
