-- Cross-check: the DecorWidgets registry contract. Every special-case entry must
-- carry a numeric itemID, a key that matches its table key, and a non-empty items
-- list; KeyFor/Get must round-trip. Guards future entries (e.g. quest chains).
-- DecorWidgets is pure data (no Store/selectors), so no full boot needed.
HDG = {}
dofile("../UI/HDGR_DecorWidgets.lua")

local DW = HDG.DecorWidgets
assert(DW, "HDG.DecorWidgets exists")

local count = 0
for key, e in pairs(DW._byKey) do
    count = count + 1
    assert(type(e.itemID) == "number", key .. ": itemID is numeric")
    assert(e.key == key, key .. ": entry.key matches its table key")
    assert(type(e.items) == "table" and #e.items > 0, key .. ": non-empty items list")
    assert(DW:KeyFor(e.itemID) == key, key .. ": KeyFor(itemID) round-trips")
    assert(DW:Get(key) == e, key .. ": Get(key) round-trips")
end
assert(count > 0, "registry has at least one entry")
print("registry contract assertions done (" .. count .. " entries)")

-- A non-registered item resolves to nil (a miss is a valid state, not an error).
assert(DW:KeyFor(1) == nil, "unregistered itemID -> nil key")

-- Shu'halo specifics: exactly 13 distinct fortunes.
local sh = DW:Get("shuhalo_fortunes")
assert(sh and #sh.items == 13, "shuhalo_fortunes has 13 items")
local seen = {}
for _, id in ipairs(sh.items) do
    assert(not seen[id], "fortune itemIDs are distinct (" .. id .. ")")
    seen[id] = true
end
print("shuhalo_fortunes assertions done")
