--[[
============================================================
Decor Vendor Addon
© 2026 MidniteDestiny. All Rights Reserved.
============================================================

This file is part of the Decor Vendor addon.

All code, structure, and design are the intellectual
property of MidniteDestiny unless otherwise stated.

You may NOT:
• Copy, reproduce, or redistribute this code
• Modify and redistribute this code
• Use this code in other addons or projects

without explicit permission from the author.

This addon is distributed for personal use only.

============================================================
]]

local addonName, dv = ...

dv.ActiveItems = dv.ActiveItems or {}

-- ============================================================
-- Build lookups from ActiveItems
-- ============================================================

function dv:BuildActiveItemLookups()
    self.vendorGoodies = {}
    self.decorToItem = {}
    self.itemToNPC = {}

    for itemID, data in pairs(self.ActiveItems or {}) do
        if self.IsDataAvailableForClient and not self.IsDataAvailableForClient(data) then
            -- Skip future/unreleased decor on older clients.
        else
            if data.decorID then
                self.decorToItem[data.decorID] = itemID
            end

            if data.soldBy then
                for _, npcID in ipairs(data.soldBy) do
                    self.vendorGoodies[npcID] = self.vendorGoodies[npcID] or {
                        items = {}
                    }

                    table.insert(self.vendorGoodies[npcID].items, itemID)
                end
            end
        end
    end
end