-- ETB Feature Registry (v15.162.0)
-- ===========================================================================
-- Single source of truth for ETB's player-facing features. Before this file,
-- the same module list was maintained independently in three places — the
-- Central Plaza (UI/LauncherPanel FEATURES), the tutorial (UI/Tutorial PAGES)
-- and the slash-command help — which is why those drifted out of sync.
--
-- Each consumer should now read from ETB.Features instead of keeping its own
-- copy:
--   * UI/LauncherPanel builds its launcher cards from the ordered list.
--   * Core/Commands resolves /etb <command> (and aliases) to a feature and
--     generates the player-facing help section.
--   * UI/Tutorial can generate its module listing (adoption pending).
--
-- Open actions are registered at runtime by the UI layer (SetAction), because
-- the functions that open each window are defined where their modules resolve.
-- This file only owns metadata (title, blurb, colour, 3D model, command,
-- aliases, group), so it can load early without depending on any UI module.
-- ===========================================================================

local ADDON_NAME, NS = ...
local ETB = NS.ETB

-- Ordered list of features (drives launcher order). `command`/`aliases` feed
-- the slash router; `group` is for future settings/tutorial sectioning.
ETB.Features = {
    { id = "transmog", title = "Transmog Browser", color = "ffffd100",
      desc = "Browse & discover appearances\nTrack collection progress",
      model = { kind = "display", display = 28641, npc = 36597, rot = -0.3 },
      command = "transmog", aliases = { "browser", "mog" }, group = "core" },

    { id = "outfits", title = "Transmog Planner", color = "ff00ff96",
      desc = "Build outfits & apply transmogs\nWorks anywhere for planning",
      model = { kind = "player", rot = 0.3 },
      command = "outfit", aliases = { "outfits", "dressup" }, group = "core" },

    { id = "bis", title = "Raid BiS Browser", color = "ff00ccff",
      desc = "BiS gear rankings by slot\nBoss tooltips & spec switching",
      model = { kind = "display", display = 47194, rot = -0.2 },
      command = "bis", aliases = { "raidbis", "erb" }, group = "core" },

    { id = "wishlist", title = "Wishlist", color = "ffffcc00",
      desc = "Items you're hunting for\nYour saved appearances",
      model = { kind = "creature", npc = 6741, rot = 0 },
      command = "wishlist", aliases = { "wish" }, group = "planning" },

    { id = "planner", title = "Collection Planner", color = "ff00ff96",
      desc = "Plan your collection goals\nPriorities & progress",
      model = { kind = "creature", npc = 29173, rot = 0 },
      command = "planner", aliases = { "plan", "goals" }, group = "planning" },

    { id = "tutorial", title = "Tutorial", color = "ff00ccff",
      desc = "Learn the addon\nTips, features & how-tos",
      model = { kind = "creature", npc = 448, rot = 0 },
      command = "tutorial", aliases = { "guide" }, group = "help" },

    { id = "mounts", title = "Mounts", color = "ffff8040",
      desc = "Mount collection tracker\nSources & drop details",
      model = { kind = "creature", npc = 19514, rot = 0 },
      command = "mounts", aliases = { "mount", "emt" }, group = "collectibles" },

    { id = "pets", title = "Pets", color = "ffff80ff",
      desc = "Battle pet tracker\nSources & drop details",
      model = { kind = "creature", npc = 14020, rot = 0 },
      command = "pets", aliases = { "pet", "ept" }, group = "collectibles" },

    { id = "toys", title = "Toys", color = "ffffcc33",
      desc = "Toy collection browser\nSources by category",
      model = { kind = "creature", npc = 32641, rot = 0 },
      command = "toys", aliases = { "toy", "etoy" }, group = "collectibles" },

    { id = "zonescan", title = "Zone Scan", color = "ff66ccff",
      desc = "Scan zones for collectibles\nAppearances by area",
      model = { kind = "creature", npc = 71515, rot = 0 },
      command = "zone", aliases = { "zonescan", "scan" }, group = "collectibles" },

    { id = "rares", title = "Rare Tracker", color = "ffcc66ff",
      desc = "Track rare spawns & timers\nDrops, respawns & alerts",
      model = { kind = "creature", npc = 32491, rot = 0 },
      command = "rares", aliases = { "rare", "ert", "raretracker" }, group = "collectibles" },
}

-- ---------------------------------------------------------------------------
-- API
-- ---------------------------------------------------------------------------
ETB.FeatureRegistry = ETB.FeatureRegistry or {}
local Registry = ETB.FeatureRegistry

-- Build lookup indexes once (by id, and by command/alias token).
local byId, byToken = {}, {}
for _, f in ipairs(ETB.Features) do
    byId[f.id] = f
    if f.command then byToken[f.command:lower()] = f.id end
    if f.aliases then
        for _, a in ipairs(f.aliases) do byToken[a:lower()] = f.id end
    end
end

local actions = {}  -- id -> open function (filled by UI layer at runtime)

function Registry:GetAll()
    return ETB.Features
end

function Registry:Get(id)
    return id and byId[id] or nil
end

-- Register the open function for a feature (called from the UI layer once its
-- module is available). Returns true if the id is a known feature.
function Registry:SetAction(id, fn)
    if byId[id] and type(fn) == "function" then
        actions[id] = fn
        return true
    end
    return false
end

-- Resolve a slash token (command or alias) to a feature id.
function Registry:ResolveCommand(token)
    if not token then return nil end
    return byToken[token:lower()]
end

-- Open a feature by id. Returns false if unknown or no action registered yet.
function Registry:Open(id)
    local fn = actions[id]
    if fn then
        fn()
        return true
    end
    return false
end

-- Convenience: open by slash token (command/alias).
function Registry:OpenByCommand(token)
    local id = self:ResolveCommand(token)
    if id then return self:Open(id) end
    return false
end
