--[[
============================================================================
ClassData.lua  (added in v14.8.0 audit Batch 2)
============================================================================

CANONICAL source of truth for class proficiency data on MoP Classic 5.4.8:
  - PRIMARY_ARMOR: which armor TYPE TOKEN (CLOTH/LEATHER/MAIL/PLATE) each
    class uses for transmog purposes
  - WEAPONS: set of weapon-type tokens each class can equip

Why this file exists:
  Prior to v14.8.0, both tables were duplicated across 6 different files:
    - Modules/OutfitCompatibility.lua  (introduced v14.3.0)
    - Modules/ProfileManager.lua
    - UI/TransmogUI.lua
    - Core/Commands.lua  (function-local!)
    - Core/BlizzardData.lua
  Adding/correcting a class proficiency required updating all 6, or
  behavior would silently diverge. Audit (v14.7.0) caught this; this
  file consolidates them.

  NOTE: Data/Categories/ArmorTypes.lua has a separate `CLASS_PRIMARY_ARMOR`
  table that uses NUMERIC subclassIDs (1=cloth, 2=leather, 3=mail, 4=plate)
  rather than string tokens, and includes future-expansion classes
  (DEMONHUNTER, EVOKER) not present on MoP. That table represents a
  different concept and is intentionally NOT consolidated here.

Format choice:
  - PRIMARY_ARMOR uses string tokens ("CLOTH"/"LEATHER"/"MAIL"/"PLATE")
    matching the dominant pattern across consumers.
  - WEAPONS uses SET form (`{ AXE = true, SWORD = true, ... }`) so that
    presence-checks (`weapons[type]`) are O(1). All 6 consumers either
    already use the set form or were migrated to it during this consolidation.
============================================================================
]]--
local ADDON_NAME, NS = ...
local ETB = NS.ETB
NS.ETB.ClassData = NS.ETB.ClassData or {}
local CD = NS.ETB.ClassData

-- =============================================================================
-- PRIMARY ARMOR (string tokens)
-- =============================================================================
CD.PRIMARY_ARMOR = {
    WARRIOR     = "PLATE",
    PALADIN     = "PLATE",
    DEATHKNIGHT = "PLATE",
    HUNTER      = "MAIL",
    SHAMAN      = "MAIL",
    ROGUE       = "LEATHER",
    DRUID       = "LEATHER",
    MONK        = "LEATHER",
    MAGE        = "CLOTH",
    WARLOCK     = "CLOTH",
    PRIEST      = "CLOTH",
}

-- =============================================================================
-- WEAPONS (set form)
-- =============================================================================
-- MoP 5.4.8 specific: thrown weapons removed in MoP, ranged/relic slot gone,
-- wands are main-hand. SHIELD is included as a "weapon" because shield
-- proficiency is class-gated the same way.
CD.WEAPONS = {
    WARRIOR     = { AXE=true, SWORD=true, MACE=true, POLEARM=true, STAFF=true, DAGGER=true, FIST=true, SHIELD=true },
    PALADIN     = { AXE=true, SWORD=true, MACE=true, POLEARM=true, SHIELD=true },
    DEATHKNIGHT = { AXE=true, SWORD=true, MACE=true, POLEARM=true },
    HUNTER      = { AXE=true, SWORD=true, POLEARM=true, STAFF=true, DAGGER=true, FIST=true, BOW=true, GUN=true, CROSSBOW=true },
    SHAMAN      = { AXE=true, MACE=true, STAFF=true, DAGGER=true, FIST=true, SHIELD=true },
    ROGUE       = { AXE=true, SWORD=true, MACE=true, DAGGER=true, FIST=true },
    DRUID       = { MACE=true, POLEARM=true, STAFF=true, DAGGER=true, FIST=true },
    MONK        = { AXE=true, SWORD=true, MACE=true, POLEARM=true, STAFF=true, FIST=true },
    MAGE        = { SWORD=true, STAFF=true, DAGGER=true, WAND=true },
    WARLOCK     = { SWORD=true, STAFF=true, DAGGER=true, WAND=true },
    PRIEST      = { MACE=true, STAFF=true, DAGGER=true, WAND=true },
}

-- =============================================================================
-- ACCESSORS
-- =============================================================================
-- Always go through these helpers when possible — they handle nil classID
-- gracefully and provide a stable surface as the data shape evolves.

-- Returns the armor token for a class, or nil if classID is unknown.
-- Callers that need a fallback should `or "CLOTH"` themselves so the
-- intent is explicit.
function CD:GetPrimaryArmor(classID)
    if not classID then return nil end
    return self.PRIMARY_ARMOR[classID]
end

-- Returns the WEAPONS set for a class, or an empty table if classID is unknown.
-- The empty fallback is safe to index (`weapons[type]` returns nil).
function CD:GetWeapons(classID)
    if not classID then return {} end
    return self.WEAPONS[classID] or {}
end

-- Convenience for the most common consumer pattern: can THIS class wield
-- THIS weapon type? Returns true/false (never nil).
function CD:ClassCanUseWeapon(classID, weaponType)
    if not classID or not weaponType then return false end
    local set = self.WEAPONS[classID]
    return set and set[weaponType] == true or false
end

-- Iterate all known classes (for /etb classtest and similar diagnostics).
-- Returns an array of class tokens in a stable display order.
local CLASS_DISPLAY_ORDER = {
    "WARRIOR", "PALADIN", "DEATHKNIGHT",
    "HUNTER", "SHAMAN",
    "ROGUE", "DRUID", "MONK",
    "MAGE", "WARLOCK", "PRIEST",
}
function CD:GetDisplayOrder()
    return CLASS_DISPLAY_ORDER
end
