local Maiden = DBM:NewBossMod("Maiden", DBM_MOV_NAME, DBM_MOV_DESCRIPTION, DBM_KARAZHAN, DBM_KARAZHAN_TAB, 3);

Maiden.Version		= "1.2";
Maiden.Author		= "Tandanu";
Maiden.LastRep		= 0;

Maiden:AddOption("HolyFireWarn", true, DBM_MOV_OPTION_2);
Maiden:AddOption("RangeCheck", true, DBM_MOV_OPTION_1, function()
	DBM:GetMod("Maiden").Options.RangeCheck = not DBM:GetMod("Maiden").Options.RangeCheck;
	
	if DBM:GetMod("Maiden").Options.RangeCheck and DBM:GetMod("Maiden").InCombat then
		DBM_Gui_DistanceFrame_Show();
	elseif not DBM:GetMod("Maiden").Options.RangeCheck and DBM:GetMod("Maiden").InCombat then
		DBM_Gui_DistanceFrame_Hide();
	end
end);


Maiden:RegisterEvents(
	"CHAT_MSG_SPELL_PERIODIC_SELF_DAMAGE",
	"CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_DAMAGE",
	"CHAT_MSG_SPELL_PERIODIC_PARTY_DAMAGE"
);

Maiden:RegisterCombat("COMBAT");

function Maiden:OnCombatStart()
	self:EndStatusBarTimer("Repentance");
	self:StartStatusBarTimer(30, "Repentance Cooldown", "Interface\\Icons\\Spell_Holy_PrayerOfHealing");
	self:ScheduleSelf(28, "RepWarning");
	
	if self.Options.RangeCheck then
		DBM_Gui_DistanceFrame_Show();
	end
end

function Maiden:OnCombatEnd()
	if self.Options.RangeCheck then
		DBM_Gui_DistanceFrame_Hide();
	end
end

function Maiden:OnEvent(event, arg1)
	if event == "RepWarning" then
		self:Announce(DBM_MOV_WARN_REP_SOON);
		
	elseif type(arg1) == "string" and string.find(arg1, DBM_MOV_REPENTANCE) and (GetTime() - 20) > self.LastRep  then
		self:Announce(DBM_MOV_WARN_REP);
		self:StartStatusBarTimer(29, "Repentance Cooldown", "Interface\\Icons\\Spell_Holy_PrayerOfHealing");						
		self:ScheduleSelf(27, "RepWarning");		
		self.LastRep = GetTime();
		
	elseif type(arg1) == "string" and string.find(arg1, DBM_MOV_DEBUFF_HOLYFIRE) and self.Options.HolyFireWarn then
		local _, _, target, isSelf = string.find(arg1, DBM_MOV_DEBUFF_HOLYFIRE);
		if target == DBM_YOU and isSelf == DBM_ARE then
			target = UnitName("player");
		end
		if target then
			self:Announce(string.format(DBM_MOV_WARN_HOLYFIRE, target));
		end		
	end
end