assert( oRA, "oRA not found!")

------------------------------
--      Are you local?      --
------------------------------

local L = AceLibrary("AceLocale-2.0"):new("oRAPBuff")

local buffs = {
	["PowerWordFortitude"] = { 1, 1},
	["PrayerOfFortitude"] = {1, 2},
	["MarkOfTheWild"] = {2, 1},
	["GiftOfTheWild"] = {2, 2},
	["ArcaneIntellect"] = {3, 1},
	["ArcaneBrilliance"] = {3, 2},
	-- 4 missing from CTRA as well.
	["ShadowProtection"] = {5, 1},
	["PrayerofShadowProtection"] = {5, 2},
	["PowerWordShield"] = {6, 0},
	["SoulstoneResurrection"] = {7, 0},
	["DivineSpirit"] = {8, 1},
	["PrayerOfSpirit"] = {8, 2},
	["Thorns"] = {9, 0},
	["FearWard"] = {10, 0},
	["BlessingOfMight"] = {11, 1},
	["GreaterBlessingOfMight"] = {11, 2},
	["BlessingOfWisdom"] = {12, 1},
	["GreaterBlessingOfWisdom"] = {12, 2},
	["BlessingOfKings"] = {13, 1},
	["GreaterBlessingOfKings"] = {13, 2},
	["BlessingOfSalvation"] = {14, 1},
	["GreaterBlessingOfSalvation"] = {14, 2},
	["BlessingOfLight"] = {15, 1},
	["GreaterBlessingOfLight"] = {15, 2},
	["BlessingOfSanctuary"] = {16, 1},
	["GreaterBlessingOfSanctuary"] = {16, 2},
	["Renew"] = {17, 0},
	["Rejuvenation"] = {18, 0},
	["Regrowth"] = {19, 0},
	["AmplifyMagic"] = {20, 0},
	["DampenMagic"] = {21, 0},
}

----------------------------
--      Localization      --
----------------------------

L:RegisterTranslations("enUS", function() return {
	["buffparticipant"] = true,
	["Participant/Buff"] = true,
	["buff"] = true,
	["Buff"] = true,
	["Options for buffs."] = true,

	["PowerWordFortitude"] = "Power Word: Fortitude",
	["PrayerOfFortitude"] = "Prayer of Fortitude",
	["GiftOfTheWild"] = "Gift of the Wild",
	["MarkOfTheWild"] = "Mark of the Wild",
	["ArcaneIntellect"] = "Arcane Intellect",
	["ArcaneBrilliance"] = "Arcane Brilliance",
	["ShadowProtection"] = "Shadow Protection",
	["PrayerofShadowProtection"] = "Prayer of Shadow Protection",
	["PowerWordShield"] = "Power Word: Shield",
	["SoulstoneResurrection"] = "Soulstone Resurrection",
	["DivineSpirit"] = "Divine Spirit",
	["PrayerOfSpirit"] = "Prayer of Spirit",
	["Thorns"] = "Thorns",
	["FearWard"] = "Fear Ward",
	["BlessingOfMight"] = "Blessing of Might",
	["GreaterBlessingOfMight"] = "Greater Blessing of Might",
	["BlessingOfWisdom"] = "Blessing of Wisdom",
	["GreaterBlessingOfWisdom"] = "Greater Blessing of Wisdom",
	["BlessingOfKings"] = "Blessing of Kings",
	["GreaterBlessingOfKings"] = "Greater Blessing of Kings",
	["BlessingOfSalvation"] = "Blessing of Salvation",
	["GreaterBlessingOfSalvation"] = "Greater Blessing of Salvation",
	["BlessingOfLight"] = "Blessing of Light",
	["GreaterBlessingOfLight"] = "Greater Blessing of Light",
	["BlessingOfSanctuary"] = "Blessing of Sanctuary",
	["GreaterBlessingOfSanctuary"] = "Greater Blessing of Sanctuary",
	["Renew"] = "Renew",
	["Rejuvenation"] = "Rejuvenation",
	["Regrowth"] = "Regrowth",
	["AmplifyMagic"] = "Amplify Magic",
	["DampenMagic"] = "Dampen Magic",
} end )

----------------------------------
--      Module Declaration      --
----------------------------------

oRAPBuff = oRA:NewModule(L["buffparticipant"])

oRAPBuff.defaults = {
}
oRAPBuff.participant = true
oRAPBuff.name = L["Participant/Buff"]
-- oRAPBuff.consoleCmd = L"buff"
-- oRAPBuff.consoleOptions = {
-- 	type = "group",
-- 	desc = L"Options for buffs.",
-- 	args = {
-- 	}
-- }


------------------------------
--      Initialization      --
------------------------------

function oRAPBuff:OnInitialize()
	self.debugFrame = ChatFrame5
end

function oRAPBuff:OnEnable()
	self:RegisterEvent("SpecialEvents_PlayerBuffGained")
	self:RegisterEvent("SpecialEvents_PlayerBuffLost")
end

function oRAPBuff:OnDisable()
	self:UnregisterAllEvents()
end

------------------------------
--      Event Handlers      --
------------------------------

function oRAPBuff:SpecialEvents_PlayerBuffGained(buff, index)
	if L:HasReverseTranslation( buff ) then
		local ourbuff = L:GetReverseTranslation( buff )
		local timeleft = floor( GetPlayerBuffTimeLeft( index ) + .5 )
		self:SendMessage( "RN " .. timeleft .. " " .. buffs[ourbuff][1] .. " " .. buffs[ourbuff][2] )
	end
end

function oRAPBuff:SpecialEvents_PlayerBuffLost(buff)
	if L:HasReverseTranslation( buff ) then
		local ourbuff = L:GetReverseTranslation( buff )
		-- we send 1 second left on this buff.
		self:SendMessage( "RN 1 ".. buffs[ourbuff][1] .. " " .. buffs[ourbuff][2] )
	end
end
