aura_env.GUIDUnitMap = {}
aura_env.PlayerName = UnitName("player")
-- Indices are class ids
---@alias ClassColor {className: string, color: {rgbInt: table<number>, rgbHex: table<number>}, rgbString: string}
---@type table<number, ClassColor>
aura_env.ClassColors = {
	{
		className = "Warrior",
		color = {
			rgbInt = { 198, 155, 109 },
			rgbHex = { 0.78, 0.61, 0.43 },
		},
		rgbString = "C69B6D",
	},
	{
		className = "Paladin",
		color = {
			rgbInt = { 244, 140, 186 },
			rgbHex = { 0.96, 0.55, 0.73 },
		},
		rgbString = "F48CBA",
	},
	{
		className = "Hunter",
		color = {
			rgbInt = { 170, 211, 114 },
			rgbHex = { 0.67, 0.83, 0.45 },
		},
		rgbString = "AAD372",
	},
	{
		className = "Rogue",
		color = {
			rgbInt = { 255, 244, 104 },
			rgbHex = { 1.00, 0.96, 0.41 },
		},
		rgbString = "FFF468",
	},
	{
		className = "Priest",
		color = {
			rgbInt = { 255, 255, 255 },
			rgbHex = { 1.00, 1.00, 1.00 },
		},
		rgbString = "FFFFFF",
	},
	{
		className = "Death Knight",
		color = {
			rgbInt = { 196, 30, 58 },
			rgbHex = { 0.77, 0.12, 0.23 },
		},
		rgbString = "C41E3A",
	},
	{
		className = "Shaman",
		color = {
			rgbInt = { 0, 112, 221 },
			rgbHex = { 0.00, 0.44, 0.87 },
		},
		rgbString = "0070DD",
	},
	{
		className = "Mage",
		color = {
			rgbInt = { 63, 199, 235 },
			rgbHex = { 0.25, 0.78, 0.92 },
		},
		rgbString = "3FC7EB",
	},
	{
		className = "Warlock",
		color = {
			rgbInt = { 135, 136, 238 },
			rgbHex = { 0.53, 0.53, 0.93 },
		},
		rgbString = "8788EE",
	},
	{
		className = "Monk",
		color = {
			rgbInt = { 0, 255, 152 },
			rgbHex = { 0.00, 1.00, 0.60 },
		},
		rgbString = "00FF98",
	},
	{
		className = "Druid",
		color = {
			rgbInt = { 255, 124, 10 },
			rgbHex = { 1.00, 0.49, 0.04 },
		},
		rgbString = "FF7C0A",
	},
	{
		className = "Demon Hunter",
		color = {
			rgbInt = { 163, 48, 201 },
			rgbHex = { 0.64, 0.19, 0.79 },
		},
		rgbString = "A330C9",
	},
}

local SoundFileRoot = "Interface\\Sounds\\spellAlert\\"

---@param guid string
---@return string, nil|string
local function GetUnitFromGuid(guid)
	local unit = aura_env.GUIDUnitMap[guid]
	if unit == nil then return "none", "Unit not found" end
	return unit, nil
end

---@param guid string
---@return {name: string, target: string, targetClassId: number, prettyTarget: string}, nil|string
local function GetTargetInfoForGuid(guid)
	local retval = {
		name = "",
		target = "",
		targetClassId = 1,
		prettyTarget = "",
	}

	local unit, err = GetUnitFromGuid(guid)
	if err then return retval, err end

	local targetUnit = string.format("%starget", unit)
	retval.target = UnitName(targetUnit)
	retval.prettyTarget = retval.target

	local targetClassId = select(3, UnitClass(targetUnit))
	retval.targetClassId = targetClassId
	---@type ClassColor
	local classColorInfo = aura_env.ClassColors[targetClassId]
	if classColorInfo then
		retval.prettyTarget = string.format("|cFF%s%s|r", classColorInfo.rgbString, retval.target)
	end

	return retval, nil
end

---@param guid string
---@return {name: string, startms: number, endms: number, spellid: number}, nil|string
local function GetCastInfoForGuid(guid)
	local retval = {
		name = "",
		startms = 0,
		endms = 0,
		spellid = 0,
	}

	local unit, err = GetUnitFromGuid(guid)
	if err then return retval, err end
	local name, _, _, _, startTimeMS, endTimeMS, _, _, _, spellId = UnitCastingInfo(unit)
	if name == nil then return retval, "Unit not casting" end

	retval.name = name
	retval.startms = startTimeMS
	retval.endms = endTimeMS
	retval.spellid = spellId

	return retval, nil
end

---@class Alert
---@field id number
---@field soundFile string
---@field events table<string, boolean>
---@field instruction string
---@field afflictedInstruction string
---@field iterator number
aura_env.Alert = {
	---@param id number
	---@param name string
	---@param events table<string>
	---@param instruction string
	---@param afflictedInstruction string
	---@return Alert
	new = function(id, name, events, instruction, afflictedInstruction)
		local self = setmetatable({}, {
			__index = aura_env.Alert,
		})
		self.id = id
		name = string.gsub(name, " ", "_")
		name = string.lower(name)
		self.soundFile = string.format("%s%s.ogg", SoundFileRoot, name)
		self.events = {}
		for _, event in ipairs(events) do
			self.events[event] = true
		end
		self.instruction = instruction
		self.afflictedInstruction = afflictedInstruction
		self.iterator = 0
		return self
	end,

	---@param self Alert
	---@param allstates allstates
	---@param ... any
	---@return string|nil
	Trigger = function(self, allstates, ...)
		-- We trust that the event is valid
		local spellname, err = CLEUParser.GetSpellName(...)
		if err then return err end

		-- The idea is:
		-- SEE C_NamePlate.GetNamePlateForUnit !!!!
		-- If the spell is being cast (SPELL_CAST_START) target will be nil (because server is cooked)
		-- So what we want to do is get the source GUID and try to find it in nameplates
		-- If it exists in nameplates we have a unitid and we can try to get casting info
		-- From the casting info we can get the cast start and end as well as get the target from unit+target
		-- However if the spell is already cast (SPELL_CAST_SUCCESS) the call to castInfo will return no info for cast
		-- But it will return info about the target
		-- Now the target itself is the actual target of the unit NOT the target of the spell
		-- We just have to assume that the target of the spell is the same as the target of the unit
		-- We then clamp the cast time to at least 1 second (meaning instant spells appear for 1s)
		-- And get the target "manually" from the instant cast using the same principle as with the cast start
		local src, err = CLEUParser.GetSourceGUID(...)
		if err then return err end
		local castInfo, err = GetCastInfoForGuid(src)
		local targetInfo, err = GetTargetInfoForGuid(src)
		DevTools_Dump(targetInfo)

		-- If the event DOES have destName then use that ACTUAL target
		-- Unless it's the same target we already got
		-- The reason we don't overwrite the same target we already got is because we can not (easily) infer
		-- The target class from the destName because we don't know where to look for the unit
		local target, err = CLEUParser.GetDestName(...)
		if err == nil and target ~= targetInfo.target then
			targetInfo.target = target
			targetInfo.prettyTarget = target
			targetInfo.targetClassId = 1
		end

		local displayText = self.instruction
		if err == nil and targetInfo.target == PlayerName then displayText = self.afflictedInstruction end

		local castEnd = math.max(GetTime() + 5, castInfo.endms / 1000)
		local castDuration = math.max(5, (castInfo.endms - castInfo.startms) / 1000)

		---@type state
		local state = {
			show = true,
			changed = true,
			progressType = "timed",
			expireTime = castEnd,
			duration = castDuration,
			autoHide = true,
			name = spellname,
			instruction = displayText,
			target = targetInfo.target,
			prettyTarget = targetInfo.prettyTarget,
			targetClassId = targetInfo.targetClassId,
		}

		allstates[string.format("%d-%d", self.id, self.iterator)] = state
		self.iterator = self.iterator + 1
		return nil
	end,
}

local alerts = {
	-- Debug
	-- aura_env.Alert.new(774, "Rejuvenation", { "SPELL_AURA_APPLIED" }, "REJUV", "REEEEEEEEJUUUUUUUUUUUVVVVVVVVV"),
	-- Garothi
	aura_env.Alert.new(244410, "Decimation", { "SPELL_CAST_SUCCESS" }, "", "Move"),
	aura_env.Alert.new(246220, "Fel Bombardment", { "SPELL_CAST_SUCCESS" }, "", "Move"),
	aura_env.Alert.new(244969, "Eradication", { "SPELL_CAST_START" }, "Run away", ""),
	aura_env.Alert.new(244106, "Carnage", { "SPELL_CAST_START" }, "Tank the boss", ""),
	aura_env.Alert.new(246664, "Annihilation", { "SPELL_CAST_SUCCESS" }, "Soak pools", ""),
	-- Felhounds
	aura_env.Alert.new(244086, "Molten Touch", { "SPELL_CAST_SUCCESS" }, "", "Run away"),
	aura_env.Alert.new(244768, "Desolate Gaze", { "SPELL_AURA_APPLIED" }, "", "Move away"),
	aura_env.Alert.new(
		244057,
		"Enflame Corruption",
		{ "SPELL_CAST_START", "SPELL_AURA_APPLIED" },
		"Spread",
		"Spread!!"
	),
	aura_env.Alert.new(244131, "Consuming Sphere", { "SPELL_AURA_APPLIED" }, "Move", ""),
	aura_env.Alert.new(244056, "Siphon Corruption", { "SPELL_CAST_START", "SPELL_AURA_APPLIED" }, "Stack", "Stack!!"),
	-- Antoran High Command
	-- aura_env.Alert.new(245161, "Entropic Mine"), -- Need more info
	-- aura_env.Alert.new(245546, "Summon Reinforcements"), -- Need more info
	-- Portal Keeper Hasabel
	aura_env.Alert.new(244016, "Reality Tear", { "SPELL_CAST_SUCCESS" }, "", ""),
	aura_env.Alert.new(243983, "Collapsing World", { "SPELL_CAST_SUCCESS" }, "Dodge", ""),
	aura_env.Alert.new(244000, "Felstorm Barrage", { "SPELL_CAST_START" }, "Dodge", ""),
	-- Imonar
	-- aura_env.Alert.new(247552, "Sleep Canister"), -- Need more info
	aura_env.Alert.new(247367, "Shock Lance", { "SPELL_CAST_SUCCESS" }, "", ""),
	aura_env.Alert.new(248068, "Empowered Pulse Grenade", { "SPELL_CAST_SUCCESS" }, "", ""), -- Need more info
	aura_env.Alert.new(247376, "Pulse Grenade", { "SPELL_CAST_SUCCESS" }, "", ""), -- Need more info
	aura_env.Alert.new(247716, "Charged Blasts", { "SPELL_AURA_APPLIED" }, "", "Move!!"),
	aura_env.Alert.new(247687, "Sever", { "SPELL_CAST_SUCCESS" }, "", ""),
	aura_env.Alert.new(248070, "Empowered Shrapnel Blast", { "SPELL_CAST_START" }, "Mines", ""),
	aura_env.Alert.new(250255, "Empowered Shock Lance", { "SPELL_CAST_START" }, "", ""),
	-- Kin'garoth
	aura_env.Alert.new(254919, "Forging Strike", { "SPELL_CAST_START" }, "", ""),
	aura_env.Alert.new(254926, "Reverberating Strike", { "SPELL_CAST_START" }, "Dodge", "Dodge"),
	-- aura_env.Alert.new(246840, "Ruiner"), -- Need more info
	-- aura_env.Alert.new(246779, "Diabolic Bomb"), -- Need more info
	-- aura_env.Alert.new(246706, "Demolish"), -- Need more info
	-- Varimathras
	aura_env.Alert.new(243960, "Shadow Strike", { "SPELL_CAST_SUCCESS" }, "Taunt", "Survive"),
	aura_env.Alert.new(243961, "Misery", { "SPELL_AURA_APPLIED" }, "", "Survive"),
	aura_env.Alert.new(244042, "Marked Prey", { "SPELL_AURA_APPLIED" }, "Do not soak", "Let someone soak"),
	-- aura_env.Alert.new(244093, "Necrotic Embrace"), -- Need more info
	-- aura_env.Alert.new(248732, "Echoes of Doom"), -- Need more info
	aura_env.Alert.new(243999, "Dark Fissure", { "SPELL_CAST_START" }, "Move", ""),
	-- Coven
	-- aura_env.Alert.new(253189, "Shivan Pact"), -- Need more info
	aura_env.Alert.new(244899, "Fiery Strike", { "SPELL_CAST_START" }, "", "Prepare"),
	aura_env.Alert.new(245627, "Whirling Saber", { "SPELL_CAST_START" }, "Dodge", ""),
	aura_env.Alert.new(245281, "Shadow Blades", { "SPELL_CAST_START" }, "Dodge", ""), -- Need more info
	aura_env.Alert.new(245586, "Chilled Blood", { "SPELL_AURA_APPLIED" }, "Heal", "Heal"),
	-- Aggramar
	-- aura_env.Alert.new(254452, "Ravenous Blaze"), -- Need more info
	aura_env.Alert.new(244693, "Wake of Flame", { "SPELL_CAST_START" }, "Dodge", "Dodge!"),
	-- aura_env.Alert.new(244291, "Foe Braker"), -- Need more info
	-- aura_env.Alert.new(244033, "Flame Rend"), -- Need more info
	-- aura_env.Alert.new(247079, "Empowered Flame Rend"), -- Need more info
	-- aura_env.Alert.new(245983, "Flare"), -- Need more info
	-- aura_env.Alert.new(246037, "Empowered Flare"), -- Need more info
	-- Argus
	-- aura_env.Alert.new(256457, "Cone of Death"), -- Need more info
	aura_env.Alert.new(248396, "Soulblight", { "SPELL_AURA_APPLIED" }, "", "Run away from group"),
	aura_env.Alert.new(257296, "Tortured Rage", { "SPELL_CAST_START" }, "Brace", ""),
	aura_env.Alert.new(251570, "Soulbomb", { "SPELL_AURA_APPLIED" }, "Brace", "Run far away from group"),

	-- Mythic+
	-- Black Rook Hold
	-- aura_env.Alert.new(225573, "Dark Mending"),
	-- aura_env.Alert.new(200105, "Sacrifice Soul"),
	-- aura_env.Alert.new(225732, "Strike Down"),
	-- aura_env.Alert.new(194996, "Soul Echoes"),
	-- aura_env.Alert.new(195254, "Swirling Scythe"),
	-- aura_env.Alert.new(194956, "Reap Soul"),
	aura_env.Alert.new(201858, "Shoot", { "SPELL_CAST_START" }, "", "LOS!"),
	-- aura_env.Alert.new(200248, "Arcane Blitz"),
	-- aura_env.Alert.new(200345, "Arrow Barrage"),
	-- aura_env.Alert.new(200291, "Knife Dance"),
	-- aura_env.Alert.new(200261, "Bonebreaking Strike"),
	-- aura_env.Alert.new(197418, "Vengeful Shear"),
	-- aura_env.Alert.new(201139, "Brutal Assault"),
	-- aura_env.Alert.new(198245, "Brutal Haymaker"),
	-- aura_env.Alert.new(198079, "Hateful Gaze"),
	-- Cathedral of Eternal Night
	-- aura_env.Alert.new(241937, "Shadow Wall"),
	-- aura_env.Alert.new(238543, "Demonic Mending"),
	-- aura_env.Alert.new(242792, "Vile Roots"),
	-- aura_env.Alert.new(236627, "Floral Fulmination"),
	-- aura_env.Alert.new(239217, "Blinding Glare"),
	-- aura_env.Alert.new(237726, "Scornful Gaze"),
	-- aura_env.Alert.new(190620, "Felblaze Orb"),
	-- aura_env.Alert.new(239268, "Venom Storm"),
	-- aura_env.Alert.new(234107, "Chaotic Energy"),
	-- aura_env.Alert.new(236543, "Felsoul Cleave"),
	-- aura_env.Alert.new(238315, "Shadow Sweep"),
	-- aura_env.Alert.new(243168, "Demonic Upheaval"),
	-- Court of Stars
	-- aura_env.Alert.new(210261, "Sound Alarm"),
	-- aura_env.Alert.new(215204, "Hinder"),
	-- aura_env.Alert.new(209027, "Quelling Strike"),
	-- aura_env.Alert.new(209516, "Mana Fang"),
	-- aura_env.Alert.new(209485, "Drain Magic"),
	-- aura_env.Alert.new(209404, "Seal Magic"),
	-- aura_env.Alert.new(209495, "Charged Smash"),
	-- aura_env.Alert.new(225100, "Charging Station"),
	-- aura_env.Alert.new(219488, "Streetsweeper"),
	-- aura_env.Alert.new(212784, "Eye Storm"),
	-- aura_env.Alert.new(211464, "Fel Detonation"),
	-- aura_env.Alert.new(207980, "Disintegration Beam"),
	-- aura_env.Alert.new(207979, "Shockwave"),
	-- aura_env.Alert.new(209628, "Piercing Gale"),
	-- aura_env.Alert.new(209676, "Slicing Maelstrom"),
	-- Darkheart Thicket
	-- aura_env.Alert.new(200631, "Unnerving Screech"),
	-- aura_env.Alert.new(200580, "Maddening Roar"),
	-- aura_env.Alert.new(191326, "Breath of Corruption"),
	-- aura_env.Alert.new(201400, "Dread Inferno"),
	-- aura_env.Alert.new(200238, "Feed on the Weak"),
	-- Eye of Azshara
	-- aura_env.Alert.new(195172, "Mighty Slam"),
	-- aura_env.Alert.new(195129, "Thundering Stomp"),
	-- aura_env.Alert.new(195046, "Rejuvenating Waters"),
	-- aura_env.Alert.new(162135, "Bellowing Roar"),
	-- aura_env.Alert.new(197105, "Polymorh Fish"),
	-- aura_env.Alert.new(193597, "Static Nova"),
	-- aura_env.Alert.new(193611, "Focused Lightning"),
	-- aura_env.Alert.new(196129, "Spray Sand"),
	-- aura_env.Alert.new(196144, "Sandstorm"),
	-- aura_env.Alert.new(196296, "Roiling Storm"),
	-- aura_env.Alert.new(196290, "Chaotic Tempest"),
	-- aura_env.Alert.new(191848, "Rampage"),
	-- Halls of Valor
	-- aura_env.Alert.new(198605, "Thunderstrike"),
	-- aura_env.Alert.new(198888, "Lightning Breath"),
	-- aura_env.Alert.new(191284, "Horn of Valor"),
	-- aura_env.Alert.new(198934, "Rune of Healing"),
	-- aura_env.Alert.new(215433, "Holy Radiance"),
	-- aura_env.Alert.new(199210, "Penetrating Shot"),
	-- aura_env.Alert.new(191976, "Arcing Bolt"),
	-- aura_env.Alert.new(192305, "Eye of the Storm"),
	-- aura_env.Alert.new(192307, "Sanctify"),
	-- aura_env.Alert.new(192048, "Expel Light"),
	-- aura_env.Alert.new(192018, "Shield of Light"),
	-- aura_env.Alert.new(196512, "Claw Frenzy"),
	-- aura_env.Alert.new(199652, "Sever"),
	-- aura_env.Alert.new(199726, "Unruly Yell"),
	-- aura_env.Alert.new(199674, "Wicked Dagger"),
	-- aura_env.Alert.new(193826, "Ragnarok"),
	-- aura_env.Alert.new(198263, "Radiant Tempest"),
	-- aura_env.Alert.new(198072, "Spear of Light"),
	-- aura_env.Alert.new(197961, "Runic Band"),
	-- aura_env.Alert.new(198750, "Surge"),
	-- Maw of Souls
	-- aura_env.Alert.new(193364, "Screams of the Dead"),
	-- aura_env.Alert.new(194442, "Six Pound Barrel"),
	-- aura_env.Alert.new(194615, "Sea Legs"),
	-- aura_env.Alert.new(192019, "Lantern of Darkness"),
	-- aura_env.Alert.new(194099, "Bile Breath"),
	-- aura_env.Alert.new(198405, "Bone Chilling Scream"),
	-- aura_env.Alert.new(194325, "Fragment"),
	-- aura_env.Alert.new(194216, "Cosmic Scythe"),
	-- aura_env.Alert.new(195293, "Debilitating Shout"),
	-- aura_env.Alert.new(185539, "Rapid Rupture"),
	-- aura_env.Alert.new(198495, "Torrent"),
	-- aura_env.Alert.new(202098, "Brackwater Barrage"),
	-- Neltharion's Lair
	-- aura_env.Alert.new(202181, "Stone Gaze"),
	-- aura_env.Alert.new(226296, "Piercing Shards"),
	-- aura_env.Alert.new(188169, "Razor Shards"),
	-- aura_env.Alert.new(198496, "Sunder"),
	-- aura_env.Alert.new(199176, "Spiked Tongue"),
	-- aura_env.Alert.new(193585, "Bound"),
	-- aura_env.Alert.new(200700, "Landslide"),
	-- aura_env.Alert.new(200732, "Molten Crash"),
	-- The Arcway
	-- aura_env.Alert.new(211771, "Prophecies of Doom"),
	-- aura_env.Alert.new(211037, "Celerity Zone"),
	-- aura_env.Alert.new(195791, "Quarantine"),
	-- aura_env.Alert.new(226285, "Demonic Ascension"),
	-- aura_env.Alert.new(197810, "Wicked Slam"),
	-- aura_env.Alert.new(211217, "Arcane Slicer"),
	-- aura_env.Alert.new(211115, "Phase Breach"),
	-- aura_env.Alert.new(196392, "Overcharge Mana"),
	-- aura_env.Alert.new(200040, "Nether Venom"),
	-- aura_env.Alert.new(200227, "Tangled Web"),
	-- aura_env.Alert.new(220871, "Unstable Mana"),
	-- Vault of the Wardens
	-- aura_env.Alert.new(193069, "Nightmares"),
	-- aura_env.Alert.new(197799, "Unleash Fury"),
	-- aura_env.Alert.new(191735, "Deafening Screech"),
	-- aura_env.Alert.new(190836, "Hatred"),
	-- aura_env.Alert.new(202913, "Fel Mortar"),
	-- aura_env.Alert.new(200898, "Teleport"),
	-- aura_env.Alert.new(199917, "Shadow Crash"),
	-- aura_env.Alert.new(202658, "Drain"),
	-- aura_env.Alert.new(194945, "Lingering Gaze"),
	-- aura_env.Alert.new(196249, "Meteor"),
	-- aura_env.Alert.new(192631, "Lava Wreath"),
	-- aura_env.Alert.new(197513, "Detonating Moonglaive"),
	-- aura_env.Alert.new(189469, "Turn Kick"),
	-- Upper Karazhan
	-- aura_env.Alert.new(230083, "Nullification"),
	-- aura_env.Alert.new(227267, "Summon Volatile Energy"),
	-- aura_env.Alert.new(227254, "Evocation"),
	-- aura_env.Alert.new(229662, "Fel Breath"),
	-- aura_env.Alert.new(36247, "Fel Fireball"),
	-- aura_env.Alert.new(227628, "Piercing Missiles"),
	-- aura_env.Alert.new(227615, "Inferno Bolt"),
	-- aura_env.Alert.new(227592, "Frostbite"),
	-- aura_env.Alert.new(228269, "Flame Wreath"),
	-- aura_env.Alert.new(227779, "Ceaseless Winter"),
	-- aura_env.Alert.new(229706, "Leech Life"),
	-- aura_env.Alert.new(229714, "Consume Magic"),
	-- aura_env.Alert.new(229159, "Chaotic Shadows"),
	-- aura_env.Alert.new(229083, "Burning Blast"),
	-- aura_env.Alert.new(229151, "Disintegrate"),
	-- Lower Karazhan
	-- aura_env.Alert.new(228221, "Severe Dusting"),
	-- aura_env.Alert.new(228225, "Sultry Heat"),
	-- aura_env.Alert.new(232153, "Kara Kazham"),
	-- aura_env.Alert.new(227987, "Dinner Bell"),
	-- aura_env.Alert.new(228025, "Heat Wave"),
	-- aura_env.Alert.new(227568, "Burning Leg Sweep"),
	-- aura_env.Alert.new(227776, "Magic Magnificent"),
	-- aura_env.Alert.new(227966, "Flashlight"),
	-- aura_env.Alert.new(228279, "Shadow Rejuvenation"),
	-- aura_env.Alert.new(228278, "Demoralizing Shout"),
	-- aura_env.Alert.new(228277, "Shackles of Servitude"),
	-- aura_env.Alert.new(226316, "Shadow Bolt Volley"),
	-- aura_env.Alert.new(227508, "Mass Repentance"),
	-- aura_env.Alert.new(227793, "Sacred Ground"),
	-- aura_env.Alert.new(227463, "Whirling Edge"),
	-- aura_env.Alert.new(227646, "Iron Whirlwind"),
	-- aura_env.Alert.new(227672, "Will Breaker"),
	-- aura_env.Alert.new(227404, "Intangible Presence"),
	-- aura_env.Alert.new(227493, "Mortal Strike"),
	-- aura_env.Alert.new(228852, "Shared Suffering"),
	-- aura_env.Alert.new(228837, "Bellowing Roar"),
}

---@type table<string, table<number, Alert>>
aura_env.EventMap = {}
for _, alert in ipairs(alerts) do
	for event, _ in pairs(alert.events) do
		if not aura_env.EventMap[event] then aura_env.EventMap[event] = {} end
		aura_env.EventMap[event][alert.id] = alert
	end
end

local function varargToString(...)
	local output = {}
	for i = 1, select("#", ...) do
		output[#output + 1] = string.format("%d = %s", i, tostring(select(i, ...)))
	end
	return table.concat(output, "; ")
end

-- C:\Users\Administrator\Seafile\Backup-WoW\Ruski\WTF\Account\phatphuckdave\SavedVariables\WeakAuras.lua
if not WeakAurasSaved then WeakAurasSaved = {} end
if not WeakAurasSaved.Cyka then WeakAurasSaved.Cyka = {} end
if not WeakAurasSaved.Cyka.CLEUExample then WeakAurasSaved.Cyka.CLEUExample = {} end
--/run WeakAurasSaved.Cyka.CLEUExample = {}
---@param spellName string
---@param spellId number
---@param subevent string
---@param ... any
aura_env.LogSpell = function(spellName, spellId, subevent, ...)
	-- table.insert(WeakAurasSaved.Cyka.CLEUExample, varargToString(spellName, spellId, subevent, ...))
end
