local _, MerfinPlus = ...
MerfinPlus = LibStub("AceAddon-3.0"):NewAddon(MerfinPlus, "MerfinPlus", "AceEvent-3.0")

MerfinPlus.BuildInfo = select(4, GetBuildInfo())

function MerfinPlus:OnInitialize()
  self.db = LibStub("AceDB-3.0"):New("MerfinPlusSaved", MerfinPlus.defaults, true)
  if self.NormalizeRaidPackLocaleSettings then
    self:NormalizeRaidPackLocaleSettings()
  end
  self:RegisterCustomFonts()
  self:RegisterCustomBars()
  self:RegisterMediaAliasesFromCallback()
  self:RegisterFonts()
  self:RegisterBars()
  self:SetupOptions()
  self:RegisterSoundPaths()
  if self.InitializeWoWSimDefaults then
    self:InitializeWoWSimDefaults()
  end
  if MerfinPlus.BuildInfo < 120000 then
    MerfinPlus:PullTimerEnable()
    MerfinPlus:LFGEnable()
  end
  if self.VersionCheckEnable then
    self:VersionCheckEnable()
  end
  if MerfinPlus.BuildInfo < 5000 and MerfinPlus.BuildInfo > 4000 then
    self:FixFontsOnLogin()
  end
  if self.CompanionBridgeEnable then
    self:CompanionBridgeEnable()
  end
end

function MerfinPlus:GetDB()
  if not self.db then
    error("[MerfinPlus] Database is not initialized yet!")
  end
  return self.db.profile
end

Merfin = Merfin or {}

Merfin.L = GetLocale()
Merfin.ForcedSoundLoc = false

local supportedLoc = {
  ["ruRU"] = true,
  ["enUS"] = true,
  ["zhCN"] = true,
}

Merfin.GetLocale = function()
  if Merfin.ForcedSoundLoc then
    return Merfin.ForcedSoundLoc
  elseif not supportedLoc[Merfin.L] then
    return "enUS"
  else
    return Merfin.L
  end
end
