-------------------------------------------------------------------------------
-- ExternalDefensives.lua
-- Multi-spell tracker group fed by SpellData_Buffs.lua: every spell tagged
-- "External Defensive" in the curated table appears in this group's
-- Defensive List (same-named IDs merge into one checkbox). SpellData is
-- the single source of truth — add/remove spells THERE.
--
-- PTR-VERIFY (buff IDs, verify OOC with real casters):
--   * Rallying Cry: cast 97462, ally-side buff believed 97463 — both in
--     the table under one checkbox; prune whichever doesn't render
--     (sound would double-fire otherwise).
--   * Aura Mastery 31821 and Zephyr 374227 ally-side auras unverified.
-------------------------------------------------------------------------------
local addonName, ns = ...

-- Voice clips (Media\Audio\Voice_<name>.ogg) keyed by spell ID; spells
-- without an entry simply have no voice callout.
local VOICE_CLIPS = {
    [31821]  = { "AuraMastery", "AuraMasteryShort" },
    [1022]   = { "BlessingOfProtection", "BlessingOfProtectionShort" },
    [6940]   = { "BlessingOfSacrifice", "BlessingOfSacrificeShort" },
    [204018] = { "BlessingOfSpellwarding", "BlessingOfSpellwardingShort" },
    [47788]  = { "GuardianSpirit", "GuardianSpiritShort" },
    [102342] = { "Ironbark" },
    [116849] = { "LifeCocoon", "LifeCocoonShort" },
    [33206]  = { "PainSuppression", "PainSuppressionShort" },
    [97462]  = { "RallyingCry", "RallyingCryShort" },
    [97463]  = { "RallyingCry", "RallyingCryShort" },
    [357170] = { "TimeDilation", "TimeDilationShort" },
    [374227] = { "Zephyr" },
}

local SPELLS = ns.SpellData.BuildSpellList("External Defensive", VOICE_CLIPS)

local allIDs = {}
local defaultSpells = {}
local hasVoiceClips = false
for _, sp in ipairs(SPELLS) do
    defaultSpells[sp.key] = true
    if sp.clip then hasVoiceClips = true end
    for _, id in ipairs(sp.ids) do
        allIDs[#allIDs + 1] = id
    end
end

ns.RegisterTracker("extdef", {
    dbPrefix      = "ed_",
    displaySpell  = 33206, -- Pain Suppression icon for previews/tree
    buffSpellIDs  = allIDs,
    spellList     = SPELLS,
    hasVoiceClips = hasVoiceClips,
    -- Voice-clip choices (Sound element, Voice mode). "full"/"short" play
    -- the per-spell bundled name clip; "External"/"Defensive" play a
    -- single fixed clip (Media\Audio\Voice_External.ogg / Voice_Defensive.ogg)
    -- on every tracked ID.
    voiceOptions  = {
        { value = "full",      name = "Buff name - full",  perSpell = "full" },
        { value = "short",     name = "Buff name - short", perSpell = "short" },
        { value = "External",  name = "External" },
        { value = "Defensive", name = "Defensive" },
    },
    frameSuffix   = "ExternalDefensives",
    label         = "External Defensives",
    defaultPos    = { "CENTER", "CENTER", 0, 0 },

    -- 12.1 preset (see Innervate for the sparse-table rationale). Groups
    -- default to an Icon(s) tracker with NO stacks text (none of the
    -- tracked auras stack). Seeded when the user first enables the group.
    preset = {
        { style = "icon", iconShowStackText = false },
    },

    defaults = {
        enabled        = false,
        barCircleColor = { 0.4, 0.85, 0.4, 1.0 },
        spells         = defaultSpells,
    },
})
