
  ---------------------------------------------
  --  rOrbs - db
  ---------------------------------------------

  -- Database (DB)

  ---------------------------------------------

  --get the addon namespace
  local addon, ns = ...

  --object container
  local db = CreateFrame("Frame")
  ns.db = db
  db.default = {}
  db.list = {}

  local wipe    = wipe
  local tinsert = tinsert
  local tremove = tremove
  local strlower = strlower

  ---------------------------------------------
  --DEFAULTS
  ---------------------------------------------

  --default orb setup
  function db:GetOrbDefaults()
    return {
      --health
      ["HEALTH"] = {
        --filling  (#120202)
        filling = {
          texture     = "Interface\\AddOns\\rOrbs\\media\\orb_filling16",
          color       = { r = 0.071, g = 0.008, b = 0.008, },
          colorAuto   = false,
        },
        --model
        model = {
          enable            = true,
          displayInfo       = 33853,
          camDistanceScale  = 1.606,
          pos_x             = 0,
          pos_y             = 0.1,
          rotation          = 0,
          portraitZoom      = 0,
          alpha             = 1.0,
        },
        --galaxies
        galaxies = {
          alpha = 1.0,
        },
        --bubbles
        bubbles = {
          alpha = 1.0,
        },
        --spark
        spark = {
          alpha = 1.0,
          color = { r = 1, g = 1, b = 1, },
          matchFillColor = false,
        },
        --highlight
        highlight = {
          alpha = 1.0,
        },
        --value
        value = {
          hideOnEmpty = true,
          hideOnFull = false,
          alpha = 1,
          top = {
            color = { r = 1, g = 1, b = 1, },
            tag = "topdef",
          },
          bottom = {
            color = { r = 0.8, g = 0.8, b = 0.8, },
            tag = "botdef",
          },
        },
      },--health end
      --power  (#003659)
      ["POWER"] = {
        --filling
        filling = {
          texture     = "Interface\\AddOns\\rOrbs\\media\\orb_filling16",
          color       = { r = 0.0, g = 0.212, b = 0.349, },
          colorAuto   = false,
        },
        --model
        model = {
          enable            = true,
          displayInfo       = 32368,
          camDistanceScale  = 0.95,
          pos_x             = 0,
          pos_y             = 0.1,
          rotation          = 0,
          portraitZoom      = 0,
          alpha             = 0.70,
        },
        --galaxies
        galaxies  = {
          alpha = 1.0,
        },
        --bubbles
        bubbles = {
          alpha = 1.0,
        },
        --spark
        spark = {
          alpha = 1.0,
          color = { r = 1, g = 1, b = 1, },
          matchFillColor = false,
        },
        --highlight
        highlight = {
          alpha = 1.0,
        },
        --value
        value = {
          hideOnEmpty = true,
          hideOnFull = false,
          alpha = 1,
          top = {
            color = { r = 1, g = 1, b = 1, },
            tag = "topdef",
          },
          bottom = {
            color = { r = 0.8, g = 0.8, b = 0.8, },
            tag = "botdef",
          },
        },
      },--power end
      --target health  (#780200)
      ["TARGET_HEALTH"] = {
        filling = {
          texture     = "Interface\\AddOns\\rOrbs\\media\\orb_filling16",
          color       = { r = 0.471, g = 0.008, b = 0.0, },
          colorAuto   = false,
        },
        model = {
          enable            = false,
          displayInfo       = 33853,
          camDistanceScale  = 1.606,
          pos_x             = 0,
          pos_y             = 0.1,
          rotation          = 0,
          portraitZoom      = 0,
          alpha             = 1.0,
        },
        galaxies  = { alpha = 0.45, },
        bubbles   = { alpha = 0.30, },
        spark     = { alpha = 1.0, color = { r = 1, g = 1, b = 1, }, matchFillColor = false, },
        highlight = { alpha = 1.0,  },
        value = {
          hideOnEmpty = true,
          hideOnFull = false,
          alpha = 1,
          top    = { color = { r = 1, g = 1, b = 1, }, tag = "topdef", },
          bottom = { color = { r = 0.8, g = 0.8, b = 0.8, }, tag = "botdef", },
        },
      },--target health end
      --pet health  (#004a1a)
      ["PET_HEALTH"] = {
        filling = {
          texture     = "Interface\\AddOns\\rOrbs\\media\\orb_filling16",
          color       = { r = 0.0, g = 0.290, b = 0.102, },
          colorAuto   = false,
        },
        model = {
          enable            = false,
          displayInfo       = 33853,
          camDistanceScale  = 1.606,
          pos_x             = 0,
          pos_y             = 0.1,
          rotation          = 0,
          portraitZoom      = 0,
          alpha             = 1.0,
        },
        galaxies  = { alpha = 0.45, },
        bubbles   = { alpha = 0.30, },
        spark     = { alpha = 1.0, color = { r = 1, g = 1, b = 1, }, matchFillColor = false, },
        highlight = { alpha = 1.0,  },
        value = {
          hideOnEmpty = true,
          hideOnFull = false,
          alpha = 1,
          top    = { color = { r = 1, g = 1, b = 1, }, tag = "topdef", },
          bottom = { color = { r = 0.8, g = 0.8, b = 0.8, }, tag = "botdef", },
        },
      },--pet health end
      --target-of-target health  (#4a3500)
      ["TOT_HEALTH"] = {
        filling = {
          texture     = "Interface\\AddOns\\rOrbs\\media\\orb_filling16",
          color       = { r = 0.290, g = 0.208, b = 0.0, },
          colorAuto   = false,
        },
        model = {
          enable            = false,
          displayInfo       = 33853,
          camDistanceScale  = 1.606,
          pos_x             = 0,
          pos_y             = 0.1,
          rotation          = 0,
          portraitZoom      = 0,
          alpha             = 1.0,
        },
        galaxies  = { alpha = 0.45, },
        bubbles   = { alpha = 0.30, },
        spark     = { alpha = 1.0, color = { r = 1, g = 1, b = 1, }, matchFillColor = false, },
        highlight = { alpha = 1.0,  },
        value = {
          hideOnEmpty = true,
          hideOnFull = false,
          alpha = 1,
          top    = { color = { r = 1, g = 1, b = 1, }, tag = "topdef", },
          bottom = { color = { r = 0.8, g = 0.8, b = 0.8, }, tag = "botdef", },
        },
      },--tot health end
    } --default end
  end

  --load the default config on loadup so the rest can initialize, the view will get updated later once the saved variables are fetched
  db.char = db:GetOrbDefaults()

  --default template
  function db:GetTemplateDefaults()
    return {
      ["pearl"] = {
        --filling
        filling = {
          texture     = "Interface\\AddOns\\rOrbs\\media\\orb_filling15",
          color       = { r = 0.8, g = 0.8, b = 1, },
          colorAuto   = false, --automatic coloring based on class/powertype
        },
        --model
        model = {
          enable            = true,
          displayInfo       = 32368,
          camDistanceScale  = 0.95,
          pos_x             = 0,
          pos_y             = 0.1,
          rotation          = 0,
          portraitZoom      = 0,
          alpha             = 1,
        },
		--galaxies
        galaxies = {
          alpha = 0,
        },
		--bubbles
        bubbles = {
          alpha = 0,
        },
        --spark
        spark = {
          alpha = 0.9,
          color = { r = 1, g = 1, b = 1, },
          matchFillColor = false,
        },
        --highlight
        highlight = {
          alpha = 0.3,
        },
        --value
        value = {
          hideOnEmpty = true,
          hideOnFull = false,
          alpha = 1,
          top = {
            color = { r = 1, g = 1, b = 1, },
            tag = "topdef",
          },
          bottom = {
            color = { r = 0.8, g = 0.8, b = 0.8, },
            tag = "botdef",
          },
        },
      },
    }
  end

  function db:GetTemplateListDefaults()
    return {
      { value = "pearl", key = "pearl", notCheckable = true, keepShownOnClick = false, },
    }
  end

  ---------------------------------------------
  --LOAD SAVED VARIABLES
  ---------------------------------------------

  --db script on variables loaded
  db:SetScript("OnEvent", function(self, event)
    if rOrbs_DB_GLOB and rOrbs_DB_GLOB.reset then
      rOrbs_DB_GLOB.reset = nil
      rOrbs_DB_GLOB = db:GetTemplateDefaults()
      rOrbs_DB_GLOB.TEMPLATE_LIST = db:GetTemplateListDefaults()
    end
    --load global data
    self.loadGlobalData()
    --load character data
    if not rOrbs_DB_CHAR then
      self.loadCharacterDataDefaults()
    else
      self.loadCharacterData()
    end
    -- Mirror this character's settings into the account-wide DB so other
    -- characters can see and import them via the character dropdown.
    C_Timer.After(0, function() db:RegisterCharSnapshot() end)
    self:UnregisterEvent("VARIABLES_LOADED")
  end)
  db:RegisterEvent("VARIABLES_LOADED")

  ---------------------------------------------
  --DB RESET
  ---------------------------------------------

  --full template reset
  db.resetTemplates = function()
    rOrbs_DB_GLOB.reset = true
    ReloadUI()
  end

  ---------------------------------------------
  --CHARACTER DATA
  ---------------------------------------------
  local function SafeUpdateOrbView()
    -- no-op: GUI panel removed
  end

  -- Class/energy color: rOrbsDB.fillingColorAuto_* mirrors filling.colorAuto (second saved var).
  local function mergeFillingColorAutoFromMirror()
    if not db.char or not rOrbsDB then return end
    local function normColorAuto(v)
      return v == true or v == 1
    end
    for _, k in ipairs({ "POWER", "HEALTH" }) do
      local ch = db.char[k]
      if ch and ch.filling then
        local fk = "fillingColorAuto_" .. k
        local mirror = rOrbsDB[fk]
        local eff
        if mirror ~= nil then
          eff = normColorAuto(mirror)
        else
          eff = normColorAuto(ch.filling.colorAuto)
        end
        ch.filling.colorAuto = eff
        rOrbsDB[fk] = eff
      end
    end
  end

  --load character data defaults
  db.loadCharacterDataDefaults = function(type)
    local data = db:GetOrbDefaults()
    if type then
      if type == "HEALTH" then
        rOrbs_DB_CHAR[type] = data[type]
        if ns.GUI then ns.GUI:ChatMsg("Health orb reset to default.") end
      elseif type == "POWER" then
        rOrbs_DB_CHAR[type] = data[type]
        if ns.GUI then ns.GUI:ChatMsg("Power orb reset to default.") end
      end
    else
      rOrbs_DB_CHAR = data
      if ns.GUI then ns.GUI:ChatMsg("Character data reset to default.") end
    end
    db.char = rOrbs_DB_CHAR
    mergeFillingColorAutoFromMirror()
    mergeSparkColorDefaults()
    --update the orb view
    SafeUpdateOrbView()

  end

  local function mergeSparkColorDefaults()
    if not db.char then return end
    local defaults = db:GetOrbDefaults()
    for _, k in ipairs({ "HEALTH", "POWER", "TARGET_HEALTH", "TOT_HEALTH", "PET_HEALTH" }) do
      local ch = db.char[k]
      local def = defaults and defaults[k]
      if ch and ch.spark and def and def.spark and def.spark.color and not ch.spark.color then
        ch.spark.color = { r = def.spark.color.r, g = def.spark.color.g, b = def.spark.color.b }
      end
      if ch and ch.spark and ch.spark.matchFillColor == nil then
        ch.spark.matchFillColor = false
      end
    end
  end

  --load character data
  db.loadCharacterData = function()
    db.char = rOrbs_DB_CHAR
    -- Ensure TARGET_HEALTH exists (backward compat with old saved variables)
    if not db.char["TARGET_HEALTH"] then
      local defaults = db:GetOrbDefaults()
      db.char["TARGET_HEALTH"] = defaults["TARGET_HEALTH"]
      rOrbs_DB_CHAR["TARGET_HEALTH"] = db.char["TARGET_HEALTH"]
    end
    -- Ensure TOT_HEALTH exists (backward compat)
    if not db.char["TOT_HEALTH"] then
      local defaults = db:GetOrbDefaults()
      db.char["TOT_HEALTH"] = defaults["TOT_HEALTH"]
      rOrbs_DB_CHAR["TOT_HEALTH"] = db.char["TOT_HEALTH"]
    end
    -- Ensure PET_HEALTH exists (backward compat)
    if not db.char["PET_HEALTH"] then
      local defaults = db:GetOrbDefaults()
      db.char["PET_HEALTH"] = defaults["PET_HEALTH"]
      rOrbs_DB_CHAR["PET_HEALTH"] = db.char["PET_HEALTH"]
    end
    if db.char.reload then
      db.char.reload = false
    end
    -- Migration: targetClassColor / totClassColor were saved as nil instead of false
    -- when checkbox was off. Nil is treated as unset → orb shows class colors while UI looks unchecked.
    -- Also: GetChecked() sometimes returns 1 (int) not true.
    -- Truthy 1 would enable class color while checkbox renders unchecked (1 == true is false in Lua).
    -- Fix: normalize anything that is not boolean true to false.
    if rOrbsDB then
      if rOrbsDB.targetClassColor ~= true then rOrbsDB.targetClassColor = false end
      if rOrbsDB.totClassColor    ~= true then rOrbsDB.totClassColor    = false end
    end
    mergeFillingColorAutoFromMirror()
    mergeSparkColorDefaults()
    --update the orb view
    SafeUpdateOrbView()

  end

  ---------------------------------------------
  --GLOBAL DATA
  ---------------------------------------------

  --load global data defaults
  db.loadGlobalDataDefaults = function()
    -- silent
    rOrbs_DB_GLOB = db:GetTemplateDefaults()
    rOrbs_DB_GLOB.TEMPLATE_LIST = db:GetTemplateListDefaults()
    db.glob = rOrbs_DB_GLOB
    db.list.template = rOrbs_DB_GLOB.TEMPLATE_LIST
  end

  --load global data
  db.loadGlobalData = function()
    rOrbs_DB_GLOB = rOrbs_DB_GLOB or db:GetTemplateDefaults()
    rOrbs_DB_GLOB.TEMPLATE_LIST = rOrbs_DB_GLOB.TEMPLATE_LIST or db:GetTemplateListDefaults()
    db.glob = rOrbs_DB_GLOB
    db.list.template = rOrbs_DB_GLOB.TEMPLATE_LIST
  end

  ---------------------------------------------
  --TEMPLATES
  ---------------------------------------------

  function db:CopyTable(source, target)
    for key, value in pairs(source) do
      if type(value) == "table" then
        target[key] = {}
        self:CopyTable(value, target[key])
      else
        target[key] = value
      end
    end
  end

  --load template func
  --name: template name
  --type: orb type
  db.loadTemplate = function(name,type)
    if not rOrbs_DB_GLOB or not name then return end
    if not rOrbs_DB_GLOB[name] then
      print(addon..": template |c003399FF"..name.."|r not found")
      return
    end
    db:CopyTable(rOrbs_DB_GLOB[name],rOrbs_DB_CHAR[type])
    print(addon..": template |c003399FF"..name.."|r loaded into "..strlower(type).." orb")
    --update the orb view
    
  end

  --save template func
  --name: template name
  --type: orb type
  db.saveTemplate = function(name,type)
    if not rOrbs_DB_GLOB or not name then return end
    --adding template
    if not rOrbs_DB_GLOB[name] then
      --create default entry first
      local data = db:GetOrbDefaults()
      rOrbs_DB_GLOB[name] = data["HEALTH"]
    end
    db:CopyTable(db.char[type],rOrbs_DB_GLOB[name])
    --adding the template name to the key-value pair list
    local nameFound = false
    for i,v in ipairs(rOrbs_DB_GLOB.TEMPLATE_LIST) do
      if v.key == name then
        nameFound = true
        break
      end
    end
    if not nameFound then
      tinsert(rOrbs_DB_GLOB.TEMPLATE_LIST, { key = name, value = name, notCheckable = true, keepShownOnClick = false, })
    end
    print(addon..": "..strlower(type).." orb data saved as template |c003399FF"..name.."|r")
    --update the panel view
    
  end

  --delete template func
  --name: template name
  db.deleteTemplate = function(name)
    if not rOrbs_DB_GLOB or not name then return end
    if not rOrbs_DB_GLOB[name] then
      print(addon..": template |c003399FF"..name.."|r not found")
      return
    end
    --setting the template to nil
    rOrbs_DB_GLOB[name] = nil
    print(addon..": template |c003399FF"..name.."|r deleted")
    --removing the template name from the key-value pair list
    local indexFound
    for i,v in ipairs(rOrbs_DB_GLOB.TEMPLATE_LIST) do
      if v.key == name then
        indexFound = i
        break
      end
    end
    if indexFound then
      tremove(rOrbs_DB_GLOB.TEMPLATE_LIST, indexFound)
    end
    --update the panel view
    
  end

  ---------------------------------------------
  --PROFILES
  ---------------------------------------------

  --[[ Profile system
       ─────────────────────────────────────────────────
       Both rOrbs_DB_CHAR and rOrbsDB are SavedVariablesPerCharacter.
       Every character therefore has fully independent settings by default.

       Profiles are stored inside rOrbs_DB_GLOB (account-wide SavedVar)
       so they can be shared and applied across characters on demand.
       Saving a profile snapshots the current character's settings.
       Loading a profile overwrites the current character's settings + ReloadUI.
  ]]

  -- Returns a unique key for the current character: "Realm-Name"
  function db:GetCharKey()
    local name  = UnitName("player") or "Unknown"
    local realm = GetRealmName()     or "Unknown"
    return realm .. "-" .. name
  end

  -- Snapshot the current rOrbsDB settings (everything, including positions/scales)
  function db:SnapshotGUI()
    local snap = {}
    if not rOrbsDB then return snap end
    for key, val in pairs(rOrbsDB) do
      if type(val) ~= "table" then
        snap[key] = val
      else
        snap[key] = {}
        db:CopyTable(val, snap[key])
      end
    end
    return snap
  end

  -- Snapshot the current orb char data (rOrbs_DB_CHAR)
  function db:SnapshotChar()
    local snap = {}
    local src  = db.char or db:GetOrbDefaults()
    db:CopyTable(src, snap)
    return snap
  end

  -- Save current settings as a named profile (stored account-wide in DB_GLOB)
  db.saveProfile = function(name)
    if not name or name == "" then return end
    rOrbs_DB_GLOB.PROFILES     = rOrbs_DB_GLOB.PROFILES     or {}
    rOrbs_DB_GLOB.PROFILE_LIST = rOrbs_DB_GLOB.PROFILE_LIST or {}

    -- Build and store the profile snapshot
    rOrbs_DB_GLOB.PROFILES[name] = {
      char = db:SnapshotChar(),
      gui  = db:SnapshotGUI(),
    }

    -- Register in list if new
    local found = false
    for _, v in ipairs(rOrbs_DB_GLOB.PROFILE_LIST) do
      if v.key == name then found = true; break end
    end
    if not found then
      tinsert(rOrbs_DB_GLOB.PROFILE_LIST, { key = name, value = name, notCheckable = true, keepShownOnClick = false })
    end

    -- Track active profile name in per-char rOrbsDB for the GUI label
    rOrbsDB.activeProfile = name

    db.list.profile = rOrbs_DB_GLOB.PROFILE_LIST
    print(addon..": Profile |c003399FF"..name.."|r saved.")
  end

  -- Load a named profile: overwrites the current character's settings + ReloadUI.
  db.loadProfile = function(name)
    if not name or name == "" then return end
    rOrbs_DB_GLOB.PROFILES = rOrbs_DB_GLOB.PROFILES or {}

    if not rOrbs_DB_GLOB.PROFILES[name] then
      print(addon..": Profile |c003399FF"..name.."|r not found.")
      return
    end
    local prof = rOrbs_DB_GLOB.PROFILES[name]

    -- Overwrite orb data in rOrbs_DB_CHAR (per-char SavedVar)
    if prof.char then
      for k in pairs(rOrbs_DB_CHAR) do rOrbs_DB_CHAR[k] = nil end
      db:CopyTable(prof.char, rOrbs_DB_CHAR)
      db.char = rOrbs_DB_CHAR
    end

    -- Overwrite GUI settings in rOrbsDB (per-char SavedVar)
    if prof.gui then
      for k, v in pairs(prof.gui) do
        rOrbsDB[k] = v
      end
    end

    -- Remember which profile is active for the GUI label
    rOrbsDB.activeProfile = name

    print(addon..": Profile |c003399FF"..name.."|r loaded. Reloading UI…")
    ReloadUI()
  end

  -- applyCharProfile is no longer used (rOrbsDB is now per-character).
  -- Kept as a no-op stub so any lingering call sites don't error.
  db.applyCharProfile = function() end

  -- Delete a named profile
  db.deleteProfile = function(name)
    if not name or name == "" then return end
    if not rOrbs_DB_GLOB.PROFILES or not rOrbs_DB_GLOB.PROFILES[name] then
      print(addon..": Profile |c003399FF"..name.."|r not found.")
      return
    end
    rOrbs_DB_GLOB.PROFILES[name] = nil
    -- Remove from list
    local idx
    for i, v in ipairs(rOrbs_DB_GLOB.PROFILE_LIST or {}) do
      if v.key == name then idx = i; break end
    end
    if idx then tremove(rOrbs_DB_GLOB.PROFILE_LIST, idx) end
    db.list.profile = rOrbs_DB_GLOB.PROFILE_LIST or {}
    print(addon..": Profile |c003399FF"..name.."|r deleted.")
  end

  -- Copy (duplicate) a profile under a new name
  db.copyProfile = function(sourceName, destName)
    if not sourceName or not destName then return end
    if not rOrbs_DB_GLOB.PROFILES or not rOrbs_DB_GLOB.PROFILES[sourceName] then
      print(addon..": Source profile |c003399FF"..sourceName.."|r not found.")
      return
    end
    local src  = rOrbs_DB_GLOB.PROFILES[sourceName]
    local dest = {}
    if src.char then dest.char = {}; db:CopyTable(src.char, dest.char) end
    if src.gui  then dest.gui  = {}; db:CopyTable(src.gui,  dest.gui)  end
    rOrbs_DB_GLOB.PROFILES[destName] = dest
    local found = false
    for _, v in ipairs(rOrbs_DB_GLOB.PROFILE_LIST or {}) do
      if v.key == destName then found = true; break end
    end
    if not found then
      tinsert(rOrbs_DB_GLOB.PROFILE_LIST, { key = destName, value = destName, notCheckable = true, keepShownOnClick = false })
    end
    db.list.profile = rOrbs_DB_GLOB.PROFILE_LIST
    print(addon..": Profile |c003399FF"..sourceName.."|r copied to |c003399FF"..destName.."|r.")
  end

  -- ─────────────────────────────────────────────────────────────────────
  --  CHARACTER SNAPSHOT SYSTEM
  --  On every login the current character's complete settings are mirrored
  --  into rOrbs_DB_GLOB.CHAR_DATA["Realm-Name"] so any character can read
  --  and import another character's data from the same account.
  -- ─────────────────────────────────────────────────────────────────────

  -- Register (or refresh) the current character's snapshot in GLOB
  function db:RegisterCharSnapshot()
    if not rOrbs_DB_GLOB then return end
    rOrbs_DB_GLOB.CHAR_DATA = rOrbs_DB_GLOB.CHAR_DATA or {}
    local key = db:GetCharKey()
    rOrbs_DB_GLOB.CHAR_DATA[key] = {
      char = db:SnapshotChar(),
      gui  = db:SnapshotGUI(),
    }
  end

  -- Return a sorted list of all known character keys ("Realm-Name")
  db.getCharList = function()
    local list = {}
    local data = rOrbs_DB_GLOB and rOrbs_DB_GLOB.CHAR_DATA
    if not data then return list end
    for k in pairs(data) do
      tinsert(list, k)
    end
    table.sort(list)
    return list
  end

  -- Load another character's saved settings into the current character, then reload
  db.loadFromChar = function(charKey)
    if not charKey or charKey == "" then return end
    local data = rOrbs_DB_GLOB and rOrbs_DB_GLOB.CHAR_DATA and rOrbs_DB_GLOB.CHAR_DATA[charKey]
    if not data then
      print(addon..": No saved data found for |c003399FF"..charKey.."|r.")
      return
    end
    -- Overwrite orb char data
    if data.char then
      for k in pairs(rOrbs_DB_CHAR) do rOrbs_DB_CHAR[k] = nil end
      db:CopyTable(data.char, rOrbs_DB_CHAR)
      db.char = rOrbs_DB_CHAR
    end
    -- Overwrite GUI + position/scale settings
    if data.gui then
      for k in pairs(rOrbsDB) do rOrbsDB[k] = nil end
      db:CopyTable(data.gui, rOrbsDB)
    end
    print(addon..": Settings loaded from |c003399FF"..charKey.."|r. Reloading UI…")
    ReloadUI()
  end

  -- Initialize / refresh profile list after glob data is loaded
  local _origLoadGlobalData = db.loadGlobalData
  db.loadGlobalData = function()
    _origLoadGlobalData()
    rOrbs_DB_GLOB.PROFILES      = rOrbs_DB_GLOB.PROFILES     or {}
    rOrbs_DB_GLOB.PROFILE_LIST  = rOrbs_DB_GLOB.PROFILE_LIST or {}
    rOrbs_DB_GLOB.CHAR_DATA     = rOrbs_DB_GLOB.CHAR_DATA    or {}
    db.list.profile = rOrbs_DB_GLOB.PROFILE_LIST
  end

  db.list.profile = {}
  db.getListProfile = function() return db.list.profile end

  ---------------------------------------------
  --LIST / MODELS
  ---------------------------------------------

  --mode list for dropdown
  db.list.model = {
    {
      key = "orbtacular",
      value = "orbtacular",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 48109, key = "purble flash orb", },
        { value = 48106, key = "blue flash orb", },
        { value = 32368, key = "pearl", },
        { value = 44652, key = "the planet", },
        { value = 47882, key = "red chocolate", },
        { value = 48254, key = "purple chocolate", },
        { value = 33853, key = "red magnet", },
        { value = 34404, key = "white magnet", },
        { value = 38699, key = "dwarf artifact", },
        { value = 20782, key = "water planet", },
        { value = 25392, key = "sahara", },
        { value = 37867, key = "cthun", },
        { value = 39108, key = "purple circus", },
        { value = 16111, key = "spore", },
        { value = 22707, key = "snow ball", },
        { value = 29308, key = "death ball", },
        { value = 25889, key = "sphere", },
        { value = 28741, key = "titan orb", },
        { value = 42486, key = "force sphere", },
        { value = 45414, key = "soulshard", },
        { value = 55036, key = "arcane orb", },
        { value = 55948, key = "purple orb", },
        { value = 56632, key = "brown chocolate", },
        { value = 60225, key = "rage orb", },
      },
    },
    {
      key = "fog",
      value = "fog",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 17010, key = "red fog", },
        { value = 17054, key = "purple fog", },
        { value = 17055, key = "green fog", },
        { value = 17286, key = "yellow fog", },
        { value = 18075, key = "turquoise fog", },
        { value = 23343, key = "white fog", },
        { value = 58827, key = "orb fog", },
      },
    },
    {
      key = "portal",
      value = "portal",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 23422, key = "red portal", },
        { value = 34319, key = "blue portal", },
        { value = 34645, key = "purple portal", },
        { value = 29074, key = "warlock portal", },
        { value = 40645, key = "soul harvest", },
        { value = 52396, key = "yellow portal", },
        { value = 58948, key = "blue portal 2", },
      },
    },
    {
      key = "swirly",
      value = "swirly",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 27393, key = "blue rune swirly", },
        { value = 28460, key = "purple swirly", },
        { value = 29561, key = "blue swirly", },
        { value = 29286, key = "white swirly", },
        { value = 39581, key = "magic swirly", },
        { value = 23310, key = "swirly cloud", },
        { value = 55752, key = "white cloud", },
      },
    },
    {
      key = "fire",
      value = "fire",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 27625, key = "green fire", },
        { value = 38327, key = "fire", },
        { value = 28639, key = "green vapor", },
        { value = 53026, key = "skull", },
      },
    },
    {
      key = "elemental",
      value = "elemental",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 17065, key = "purple naaru", },
        { value = 17871, key = "white naaru", },
        { value = 1070,  key = "fire elemental", },
        { value = 14252, key = "purple elemental", },
        { value = 19003, key = "white elemental", },
        { value = 15406, key = "light-green elemental", },
        { value = 17045, key = "red elemental", },
        { value = 9449,  key = "green elemental", },
        { value = 4629,  key = "shadow elemental", },
        { value = 22731, key = "glow elemental", },
        { value = 16635, key = "void walker", },
        { value = 16170, key = "green ghost", },
        { value = 24905, key = "fire guard", },
        { value = 31450, key = "flaming bone guard", },
        { value = 34942, key = "bound fire elemental", },
        { value = 36345, key = "bound water elemental", },
        { value = 53456, key = "wod fire elemental", },
        { value = 58534, key = "magma elemental", },
      },
    },
    {
      key = "crystal",
      value = "crystal",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 17856, key = "blue crystal", },
        { value = 20900, key = "green crystal", },
        { value = 22506, key = "purple crystal", },
        { value = 26419, key = "health crystal", },
        { value = 26418, key = "power crystal", },
      },
    },
    {
      key = "aquarium",
      value = "aquarium",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 4878,  key = "fish", },
        { value = 7449,  key = "deviat", },
      },
    },
    {
      key = "unique",
      value = "unique",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 10992, key = "diablo", },
        { value = 38803, key = "murcablo", },
        { value = 5233,  key = "blue angel", },
        { value = 6888,  key = "alarm-o-bot", },
        { value = 11986, key = "molten giant", },
        { value = 38594, key = "magma giant", },
        { value = 28641, key = "algalon", },
        { value = 31094, key = "spectral bear", },
        { value = 28890, key = "mimiron head", },
        { value = 32913, key = "therazane", },
        { value = 38150, key = "fire kitten", },
        { value = 38187, key = "orange fire helldog", },
        { value = 38189, key = "blue fire helldog", },
        { value = 39354, key = "deathwing lava claw", },
        { value = 40924, key = "cranegod", },
        { value = 38548, key = "burning blob", },
        { value = 1824,  key = "blue wisp", },
        { value = 49084,  key = "robot", },
      },
    },
    {
      key = "sparkling",
      value = "sparkling",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 26753, key = "spark", },
        { value = 27617, key = "yellow spark", },
        { value = 51486, key = "creme spark", },
        { value = 46920, key = "purple splash", },
        { value = 48210, key = "yellow plasma", },
        { value = 29612, key = "strobo", },
        { value = 41110, key = "strobo2", },
        { value = 44465, key = "strobo3", },
        { value = 30792, key = "hammer of wrath", },
        { value = 47891, key = "aqua spark", },
        { value = 57891, key = "orb spark", },
        { value = 60361, key = "yellow orb spark", },
      },
    },
    {
      key = "spirit",
      value = "spirit",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 2421,  key = "killrock eye", },
        { value = 46174, key = "darkmoon eye", },
        { value = 21485, key = "blue soul", },
        { value = 30150, key = "red soul", },
        { value = 39740, key = "red spirit", },
        { value = 39738, key = "blue spirit", },
        { value = 28089, key = "ghost skull", },
        { value = 51370, key = "red snake spirit", },
      },
    },
    {
      key = "environment",
      value = "environment",
      hasArrow = true,
      notCheckable = true,
      menuList = {
        { value = 35741, key = "fire flower", },
        { value = 36405, key = "oasis flower", },
        { value = 42785, key = "icethorn flower", },
        { value = 39014, key = "purple mushroom", },
        { value = 36901, key = "purple lantern", },
        { value = 36902, key = "turquoise lantern", },
        { value = 31905, key = "purple egg", },
        { value = 34010, key = "orange egg", },
        { value = 26506, key = "bubble torch", },
        { value = 41853, key = "onyx statue", },
        { value = 51406, key = "melting pot", },
        { value = 53769, key = "white flower", },
      },
    },
  }
  db.getListModel = function() return db.list.model end

  ---------------------------------------------
  --LIST / FILLING TEXTURES
  ---------------------------------------------

  --filling texture list for dropdown
  db.list.filling_texture = {
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling1",  key = "moon", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling2",  key = "earth", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling3",  key = "mars", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling4",  key = "galaxy", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling5",  key = "jupiter", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling6",  key = "fraktal circle", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling7",  key = "sun", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling8",  key = "icecream", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling9",  key = "marble", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling10", key = "gradient", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling11", key = "bubbles", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling12", key = "woodpepples", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling13", key = "golf", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling14", key = "darkstar", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling15", key = "diablo3", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling16", key = "fubble", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling17", key = "silver", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling18", key = "exile", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling19", key = "dominion", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling20", key = "runes", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling21", key = "sigil orb", },
    { value = "Interface\\AddOns\\rOrbs\\media\\orb_filling22", key = "NelsonNetto", },
	{ value = "Interface\\AddOns\\rOrbs\\media\\orb_transparent", key = "transparent", },
  }
  db.getListFillingTexture = function() return db.list.filling_texture end

  ---------------------------------------------
  --LIST / TEMPLATEs
  ---------------------------------------------

  db.list.template = {} --reference for later
  db.getListTemplate = function() return db.list.template end

  ---------------------------------------------
  --LIST / HEALTH TAGs
  ---------------------------------------------

  --health tag list for dropdown
  db.list.tag = {
    { value = "topdef", key = "Top default", },
    { value = "botdef", key = "Bottom default", },
    { value = "per",    key = "Percentage", },
    { value = "perp",   key = "Percentage + %", },
    { value = "cur",    key = "Current value", },
    { value = "curs",   key = "Current value short", },
    { value = "max",    key = "Maximum value", },
    { value = "maxs",   key = "Maximum value short", },
    { value = "cmax",   key = "Current/Maximum value", },
    { value = "cmaxs",  key = "Current/Maximum value short", },
    { value = "null",   key = "Nothing", },
  }
  db.getListTag = function() return db.list.tag end
