local mod	= DBM:NewMod("MaexxnaVanilla", "DBM-Raids-Vanilla", 1)
local L		= mod:GetLocalizedStrings()

if DBM:IsSeasonal("SeasonOfDiscovery") then
	mod.statTypes = "normal,heroic,mythic"
else
	mod.statTypes = "normal"
end

mod:SetRevision("20260527072013")
mod:SetMinSyncRevision(20260523000000) -- 2026, May 23rd
mod:DisableHardcodedOptions()
mod:SetCreatureID(15952)
mod:SetEncounterID(1116)
mod:SetModelID(15928)
mod:SetZone(533)

mod:RegisterCombat("combat")

mod:RegisterEventsInCombat(
	"SPELL_AURA_APPLIED 28622 28747",
	"SPELL_CAST_SUCCESS 29484",
	"UNIT_SPELLCAST_SUCCEEDED"
)

local warnWebWrap		= mod:NewTargetAnnounce(28622, 2, nil, "RangedDps|Healer")
local warnEnrage 		= mod:NewSpellAnnounce(28747, 4)
local warnEnrageSoon	= mod:NewSoonAnnounce(28747, 2)
local warnSpidersNow	= mod:NewSpellAnnounce(29434, 4, "134321")
local warnSpidersSoon	= mod:NewSoonAnnounce(29434, 2, "134321")
local warnWebSprayNow	= mod:NewSpellAnnounce(29484, 4)
local warnWebSpraySoon	= mod:NewSoonAnnounce(29484, 3)

local specWarnWebWrap	= mod:NewSpecialWarningSwitch(28622, "RangedDps|Healer", nil, 2, 1, 2, nil, nil, "targetchange")
local specWarnSpiders	= mod:NewSpecialWarningAdds(29434, "Dps", nil, nil, 2, 2, nil, "134321", "killmob")
local yellWebWrap		= mod:NewYell(28622)

local timerWebSpray		= mod:NewNextTimer(40.5, 29484, nil, nil, nil, 2)
local timerWebWrap		= mod:NewVarTimer("v39.6-40.9", 28622, nil, "RangedDps|Healer", nil, 3)
local timerSpider		= mod:NewNextTimer(30.7, 29434, nil, nil, nil, 1, "134321")

mod.vb.warnEnrageSoon = false

function mod:OnCombatStart()
	self.vb.warnEnrageSoon = false
	warnWebSpraySoon:Schedule(35.5)
	timerWebSpray:Start()
	timerWebWrap:Start("v18.2-20.1")
	warnSpidersSoon:Schedule(25.7)
	timerSpider:Start()
	self:RegisterShortTermEvents(
		"UNIT_HEALTH"
	)
end

function mod:OnCombatEnd()
	self:UnregisterShortTermEvents()
end

function mod:SPELL_AURA_APPLIED(args)
	if args:IsSpell(28622) then
		warnWebWrap:CombinedShow(0.5, args.destName)
		if args.destName == UnitName("player") then
			specWarnWebWrap:Cancel()
			specWarnWebWrap:CancelVoice()
			yellWebWrap:Yell()
		elseif self:AntiSpam(3, 1) then
			specWarnWebWrap:Schedule(0.5)
			specWarnWebWrap:ScheduleVoice(0.5, "targetchange")
			timerWebWrap:Start()
		end
	elseif args:IsSpell(28747) then
		warnEnrage:Show()
	end
end

function mod:SPELL_CAST_SUCCESS(args)
	if args:IsSpell(29484)then -- Web Spray
		warnWebSprayNow:Show()
		warnWebSpraySoon:Schedule(35.5)
		timerWebSpray:Start()
		warnSpidersSoon:Schedule(25.7)
		timerSpider:Start()
	end
end

function mod:UNIT_SPELLCAST_SUCCEEDED(_, _, spellId)
	if spellId == 29434 then
		self:SendSync("SpidersNow")
	end
end

function mod:UNIT_HEALTH(uId)
	if self:GetUnitCreatureId(uId) == 15952 and UnitHealth(uId) / UnitHealthMax(uId) <= 0.35 then
		self:SendSync("EnrageSoon")
		self:UnregisterShortTermEvents()
	end
end

function mod:OnSync(msg)
	if not self:IsInCombat() then return end
	if msg == "EnrageSoon" and not self.vb.warnEnrageSoon then
		self.vb.warnEnrageSoon = true
		warnEnrageSoon:Show()
	elseif msg == "SpidersNow" then
		timerSpider:Stop()
		if self.Options.SpecWarn29434adds then
			specWarnSpiders:Show()
			specWarnSpiders:Play("killmob")
		else
			warnSpidersNow:Show()
		end
	end
end
