-- =========================================
-- DecorVendor - Debug Tools
-- =========================================

local addonName, dv = ...

local ENABLE_DEBUG = false
if not ENABLE_DEBUG then return end

function dv.DebugItemRequirement(itemID)
    if not dv or not dv.ActiveItems then return end

    local itemData = dv.ActiveItems[itemID]

    if not itemData then
        print("❌ Item not found:", itemID)
        return
    end

    local req = itemData.requirement

    if not req then
        print("ℹ️ No requirement for item:", itemID)
        return
    end

    if req.type == "renown" then
        local factionID = dv.renownFactionIDs[req.faction]
        local playerRenown = dv.GetPlayerRenownLevel(factionID)

        print("===== RENOWN DEBUG =====")
        print("Item:", itemID)
        print("Faction:", req.faction)
        print("Required:", req.level)
        print("Player:", playerRenown)

        if not factionID then
            print("❌ Missing factionID mapping!")
        end

    elseif req.type == "reputation" then
        print("===== REPUTATION DEBUG =====")
        print("Item:", itemID)
        print("Faction:", req.faction)
        print("Required Rank:", dv.reputationRanks[req.rank] or "UNKNOWN")

    elseif req.type == "subfaction" then
        local name = dv.subfactionRanks[req.faction] and dv.subfactionRanks[req.faction][req.tier]

        print("===== SUBFACTION DEBUG =====")
        print("Item:", itemID)
        print("Faction:", req.faction)
        print("Required Tier:", name or "UNKNOWN")
    end
end


SLASH_DVDEBUG1 = "/dvdebug"

SlashCmdList["DVDEBUG"] = function(msg)
    local itemID = tonumber(msg)

    if not itemID then
        print("Usage: /dvdebug 248333")
        return
    end

    dv.DebugItemRequirement(itemID)
end