local AddOnName, nsVars = ...
local ss = nsVars.SS

local setmetatable = setmetatable
local strlower = strlower

local mtClassResources = {
  classModes = {
    ["deathknight"] = {
      ["1"] = { --blood
        ["default"] = { {0, ss.ClassResourceData.classColor("death knight")}, ss.ClassResourceData.resourceInfo("runic power"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("death knight")}, ss.ClassResourceData.resourceInfo("runic power"), },
      },
      ["2"] = { --frost
        ["default"] = { {0, ss.ClassResourceData.classColor("death knight")}, ss.ClassResourceData.resourceInfo("runic power"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("death knight")}, ss.ClassResourceData.resourceInfo("runic power"), },
      },
      ["3"] = { --unholy
        ["default"] = { {0, ss.ClassResourceData.classColor("death knight")}, ss.ClassResourceData.resourceInfo("runic power"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("death knight")}, ss.ClassResourceData.resourceInfo("runic power"), },
      },
    },
    ["demonhunter"] = {
      ["1"] = { --havoc
        ["default"] = { {0, ss.ClassResourceData.classColor("demonhunter")}, ss.ClassResourceData.resourceInfo("fury"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("demonhunter")}, ss.ClassResourceData.resourceInfo("fury"), },
      },
      ["2"] = { --vengeance
        ["default"] = { {0, ss.ClassResourceData.classColor("demonhunter")}, ss.ClassResourceData.resourceInfo("pain"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("demonhunter")}, ss.ClassResourceData.resourceInfo("pain"), },
      },
    },
    ["druid"] = {
      ["1"] = { --balance
        ["default"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("mana"), ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("lunar power"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("mana"), ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("lunar power"), },
        ["bear"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("rage"), ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("mana"), },
        ["cat"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("lunar power"), ss.ClassResourceData.resourceInfo("mana"), },
        ["moonkin"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("lunar power"), ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["2"] = { --feral
        ["default"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("mana"), ss.ClassResourceData.resourceInfo("energy"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("mana"), ss.ClassResourceData.resourceInfo("energy"), },
        ["bear"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("rage"), ss.ClassResourceData.resourceInfo("energy"), },
        ["cat"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("mana"), },
        ["moonkin"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("lunar power"), ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["3"] = { --guardian
        ["default"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("mana"), ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("rage"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("mana"), ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("rage"), },
        ["bear"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("rage"), ss.ClassResourceData.resourceInfo("mana"), },
        ["cat"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("rage"), },
        ["moonkin"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("lunar power"), ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("rage"), },
      },
      ["4"] = { --restoration
        ["default"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("mana"), ss.ClassResourceData.resourceInfo("energy"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("mana"), ss.ClassResourceData.resourceInfo("energy"), },
        ["bear"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("rage"), ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("mana"), },
        ["cat"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("mana"), },
        ["moonkin"] = { {0, ss.ClassResourceData.classColor("druid")}, ss.ClassResourceData.resourceInfo("lunar power"), ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("mana"), },
      },
    },
    ["hunter"] = {
      ["1"] = { --beast mastery
        ["default"] = { {0, ss.ClassResourceData.classColor("hunter")}, ss.ClassResourceData.resourceInfo("focus"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("hunter")}, ss.ClassResourceData.resourceInfo("focus"), },
      },
      ["2"] = { --marksmanship
        ["default"] = { {0, ss.ClassResourceData.classColor("hunter")}, ss.ClassResourceData.resourceInfo("focus"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("hunter")}, ss.ClassResourceData.resourceInfo("focus"), },
      },
      ["3"] = { --survival
        ["default"] = { {0, ss.ClassResourceData.classColor("hunter")}, ss.ClassResourceData.resourceInfo("focus"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("hunter")}, ss.ClassResourceData.resourceInfo("focus"), },
      },
    },
    ["mage"] = {
      ["1"] = { --arcane
        ["default"] = { {0, ss.ClassResourceData.classColor("mage")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("mage")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["2"] = { --fire
        ["default"] = { {0, ss.ClassResourceData.classColor("mage")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("mage")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["3"] = { --frost
        ["default"] = { {0, ss.ClassResourceData.classColor("mage")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("mage")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
    },
    ["monk"] = {
      ["1"] = { --brewmaster
        ["default"] = { {0, ss.ClassResourceData.classColor("monk")}, ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("monk")}, ss.ClassResourceData.resourceInfo("energy"), ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["2"] = { -- mistweaver
        ["default"] = { {0, ss.ClassResourceData.classColor("monk")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("monk")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["3"] = { --windwalker
        ["default"] = { {0, ss.ClassResourceData.classColor("monk")}, ss.ClassResourceData.resourceInfo("energy"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("monk")}, ss.ClassResourceData.resourceInfo("energy"), },
      },
    },
    ["paladin"] = {
      ["1"] = { --holy
        ["default"] = { {0, ss.ClassResourceData.classColor("paladin")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("paladin")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["2"] = { --protection
        ["default"] = { {0, ss.ClassResourceData.classColor("paladin")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("paladin")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["3"] = { --retribution
        ["default"] = { {0, ss.ClassResourceData.classColor("paladin")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("paladin")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
    },
    ["priest"] = {
      ["1"] = { -- discipline
        ["default"] = { {0, ss.ClassResourceData.classColor("priest")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("priest")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["2"] = { --holy
        ["default"] = { {0, ss.ClassResourceData.classColor("priest")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("priest")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["3"] = { --shadow
        ["default"] = { {0, ss.ClassResourceData.classColor("priest")}, ss.ClassResourceData.resourceInfo("insanity"), ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("priest")}, ss.ClassResourceData.resourceInfo("insanity"), ss.ClassResourceData.resourceInfo("mana"), },
      },
    },
    ["rogue"] = {
      ["1"] = { --assassination
        ["default"] = { {0, ss.ClassResourceData.classColor("rogue")}, ss.ClassResourceData.resourceInfo("energy"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("rogue")}, ss.ClassResourceData.resourceInfo("energy"), },
      },
      ["2"] = { --outlaw
        ["default"] = { {0, ss.ClassResourceData.classColor("rogue")}, ss.ClassResourceData.resourceInfo("energy"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("rogue")}, ss.ClassResourceData.resourceInfo("energy"), },
      },
      ["3"] = { --subtlety
        ["default"] = { {0, ss.ClassResourceData.classColor("rogue")}, ss.ClassResourceData.resourceInfo("energy"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("rogue")}, ss.ClassResourceData.resourceInfo("energy"), },
      },
    },
    ["shaman"] = {
      ["1"] = { --elemental
        ["default"] = { {0, ss.ClassResourceData.classColor("shaman")}, ss.ClassResourceData.resourceInfo("maelstrom"), ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("shaman")}, ss.ClassResourceData.resourceInfo("maelstrom"), ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["2"] = { --enhancement
        ["default"] = { {0, ss.ClassResourceData.classColor("shaman")}, ss.ClassResourceData.resourceInfo("maelstrom"), ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("shaman")}, ss.ClassResourceData.resourceInfo("maelstrom"), ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["3"] = { --restoration
        ["default"] = { {0, ss.ClassResourceData.classColor("shaman")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("shaman")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
    },
    ["warlock"] = {
      ["1"] = { --affliction
        ["default"] = { {0, ss.ClassResourceData.classColor("warlock")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("warlock")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["2"] = { --demonology
        ["default"] = { {0, ss.ClassResourceData.classColor("warlock")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("warlock")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
      ["3"] = { --destruction
        ["default"] = { {0, ss.ClassResourceData.classColor("warlock")}, ss.ClassResourceData.resourceInfo("mana"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("warlock")}, ss.ClassResourceData.resourceInfo("mana"), },
      },
    },
    ["warrior"] = {
      ["1"] = { --arms
        ["default"] = { {0, ss.ClassResourceData.classColor("warrior")}, ss.ClassResourceData.resourceInfo("rage"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("warrior")}, ss.ClassResourceData.resourceInfo("rage"), },
      },
      ["2"] = { --fury
        ["default"] = { {0, ss.ClassResourceData.classColor("warrior")}, ss.ClassResourceData.resourceInfo("rage"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("warrior")}, ss.ClassResourceData.resourceInfo("rage"), },
      },
      ["3"] = { --protection
        ["default"] = { {0, ss.ClassResourceData.classColor("warrior")}, ss.ClassResourceData.resourceInfo("rage"), },
        ["combat"] = { {0, ss.ClassResourceData.classColor("warrior")}, ss.ClassResourceData.resourceInfo("rage"), },
      },
    },
  },
};

mtClassResources.getModes = function(self, class)
  return self.classModes[strlower(class)]
end

mtClassResources.hasSecondaryResource = function()
  return ss.db.additionalResource.modes[ss.curSpec] and ss.db.additionalResource.modes[ss.curSpec]["default"] or false
end

function mtClassResources.modeResourceUnitId(dbConfig)
  if dbConfig == "mainResource" then
    local resource = mtClassResources.classModes[strlower(ss.curClass)][strlower(ss.curSpec)][ss.curShapeshift or "default"]
    return resource[2] and resource[2][1] or 0
  elseif dbConfig == "additionalResource" then
    local resource = mtClassResources.classModes[strlower(ss.curClass)][strlower(ss.curSpec)][ss.curShapeshift or "default"]
    return (resource[3] and resource[3][1] or 0), (resource[4] and resource[4][1] or 0)
  else
    return 0, 0
  end
end

ss["ClassResources"] = setmetatable({}, { __index = mtClassResources });
