local ADDON_NAME, _ = ...
local PvPScout = CreateFrame("Frame")
PvPScout:SetScript("OnEvent", function(self, event, ...)
  if self[event] then
    self[event](self, ...)
  end
end)

PvPScout:RegisterEvent("ADDON_LOADED")
PvPScout:RegisterEvent("PLAYER_LOGIN")

local function InitSavedVariables()
  if not PvPScoutDB then
    PvPScoutDB = {
      enabled = true,
      region = nil, -- auto-detect from client
      brackets = { "2v2", "3v3", "shuffle", "rbg", "blitz" },
      showRank = true,
      color = { r = 1, g = 0.82, b = 0 }, -- gold
    }
  end
end

function PvPScout:ADDON_LOADED(name)
  if name ~= ADDON_NAME then return end
  InitSavedVariables()
end

function PvPScout:PLAYER_LOGIN()
  -- Determine region by realm list
  local realmList = GetCVar("portal")
  -- Possible values: US, EU, KR, TW, CN (CN unsupported for BNet API)
  if realmList and realmList ~= "" then
    PvPScoutDB.region = PvPScoutDB.region or string.lower(realmList)
  end
end

-- Public API
_G.PvPScout = PvPScout
