local mod	= DBM:NewMod(2437, "DBM-Party-Shadowlands", 9, 1194)
local L		= mod:GetLocalizedStrings()

mod:SetRevision("20250916083839")
mod:SetCreatureID(175616)
mod:SetEncounterID(2425)
mod:SetHotfixNoticeRev(20250916000000)
mod:SetZone(2441)

mod:RegisterCombat("combat")

mod:RegisterEventsInCombat(
	"SPELL_CAST_START 346204 1236348 348350",
	"SPELL_CAST_SUCCESS 346006",
	"SPELL_AURA_APPLIED 347949 348128 345770 345990",
	"SPELL_AURA_REMOVED 345770 345990",
	"SPELL_PERIODIC_DAMAGE 348366",
	"SPELL_PERIODIC_MISSED 348366"
)

--Improve/add timers for armed/disarmed phases because it'll probably alternate a buffactive timer instead of CD
--TODO, what do with https://ptr.wowhead.com/spell=347964/rotary-body-armor ?
--[[
(ability.id = 348350 or ability.id = 346204 or ability.id = 1236348) and type = "begincast"
 or ability.id = 346006 and type = "cast"
 or ability.id = 345990 and (type = "applydebuff" or type = "removedebuff")
 or type = "dungeonencounterstart" or type = "dungeonencounterend"
--]]
local warnArmedSecurity				= mod:NewSpellAnnounce(346204, 2)
local warnFullyArmed				= mod:NewSpellAnnounce(348128, 3, nil, "Tank|Healer")
local warnContainmentCell			= mod:NewTargetNoFilterAnnounce(345990)--When cell forms
local warnInpoundContraband			= mod:NewTargetNoFilterAnnounce(345770, 2)--Not filtered, because if it's on a tank or healer its kinda important
local warnInpoundContrabandEnded	= mod:NewEndAnnounce(345770, 1)

local specWarnInterrogation			= mod:NewSpecialWarningRun(348350, nil, nil, nil, 4, 2)
local yellInterrogation				= mod:NewYell(348350)
local specWarnInterrogationOther	= mod:NewSpecialWarningSwitchCustom(348350, "Dps", nil, nil, 1, 2)
local specWarnContainmentCell		= mod:NewSpecialWarningYou(345990, false, nil, nil, 1, 2)--Optional, but probably don't need, you already know it's you from targetting debuff
local specWarnInpoundContraband		= mod:NewSpecialWarningYou(345770, nil, nil, nil, 1, 2)
local specWarnChargedSlash			= mod:NewSpecialWarningDodge(1236348, nil, nil, nil, 2, 15)
local specWarnGTFO					= mod:NewSpecialWarningGTFO(348366, nil, nil, nil, 1, 8)

local timerInterrogationCD			= mod:NewCDTimer(40.1, 348350, nil, nil, nil, 3)
local timerArmedSecurityCD			= mod:NewVarTimer("v34.4-53", 346204, nil, nil, nil, 6)
local timerImpoundContrabandCD		= mod:NewVarTimer("v26.7-35.8", 345770, nil, nil, nil, 3)--Can't be cast if containment is still active
local timerChargedSlashCD			= mod:NewVarTimer("v17-24.4", 1236348, nil, nil, nil, 3)
--local timerStichNeedleCD			= mod:NewAITimer(15.8, 320200, nil, nil, nil, 5, nil, DBM_COMMON_L.HEALER_ICON)--Basically spammed

function mod:OnCombatStart(delay)
	timerArmedSecurityCD:Start(7.2-delay)
	timerChargedSlashCD:Start(12.1-delay)
	timerImpoundContrabandCD:Start(18.1-delay)
	timerInterrogationCD:Start(39.8-delay)
end

function mod:SPELL_CAST_START(args)
	local spellId = args.spellId
	if spellId == 346204 then
		warnArmedSecurity:Show()
		timerArmedSecurityCD:Start()
	elseif spellId == 1236348 then
		specWarnChargedSlash:Show()
		specWarnChargedSlash:Play("frontal")
		timerChargedSlashCD:Start()
	elseif spellId == 348350 then
		timerInterrogationCD:Start()
	end
end

function mod:SPELL_CAST_SUCCESS(args)
	local spellId = args.spellId
	if spellId == 346006 then
		timerImpoundContrabandCD:Start()
	end
end

function mod:SPELL_AURA_APPLIED(args)
	local spellId = args.spellId
	if spellId == 347949 and args:IsDestTypePlayer() then
		if args:IsPlayer() then
			specWarnInterrogation:Show()
			specWarnInterrogation:Play("targetyou")
			yellInterrogation:Yell()
		else
			specWarnInterrogationOther:Show(args.destName)
			specWarnInterrogationOther:Play("targetchange")
		end
	elseif spellId == 348128 then
		warnFullyArmed:Show()
	elseif spellId == 345770 then
		warnInpoundContraband:CombinedShow(0.3, args.destName)
		if args:IsPlayer() then
			specWarnInpoundContraband:Show()
			specWarnInpoundContraband:Play("targetyou")
		end
	elseif spellId == 345990 then
		timerInterrogationCD:Stop()
		timerImpoundContrabandCD:Stop()
		timerArmedSecurityCD:Stop()
		timerChargedSlashCD:Stop()
		--Timers resume on removal
		if args:IsPlayer() then
			specWarnContainmentCell:Show()
			specWarnContainmentCell:Play("targetyou")
		else
			warnContainmentCell:Show(args.destName)
		end
	end
end

function mod:SPELL_AURA_REMOVED(args)
	local spellId = args.spellId
	if spellId == 345770 then
		if args:IsPlayer() then
			warnInpoundContrabandEnded:Show()
		end
	elseif spellId == 345990 then--Containment Cell
		timerArmedSecurityCD:Start(7)
		timerChargedSlashCD:Start(12.7)
		timerImpoundContrabandCD:Start(21)
		timerInterrogationCD:Start(32.5)
	end
end

function mod:SPELL_PERIODIC_DAMAGE(_, _, _, _, destGUID, _, _, _, spellId, spellName)
	if spellId == 348366 and destGUID == UnitGUID("player") and self:AntiSpam(2, 1) then
		specWarnGTFO:Show(spellName)
		specWarnGTFO:Play("watchfeet")
	end
end
mod.SPELL_PERIODIC_MISSED = mod.SPELL_PERIODIC_DAMAGE
