-- COMBAT_LOG_EVENT_UNFILTERED
function(
	allstates,
	event,
	timestamp,
	eventtype,
	hideCaster,
	srcGUID,
	srcName,
	srcFlags,
	srcRaidFlags,
	dstGUID,
	dstName,
	dstFlags,
	dstRaidFlags,
	...
)
	aura_env.rayActive = true
	if aura_env.debug and aura_env.rayActive then
		print(string.format("aura_env.rayActive: %s, eventtype: %s", tostring(aura_env.rayActive), tostring(eventtype)))
	end
	-- if aura_env.debug then aura_env.rayActive = true end
	if aura_env.rayActive and (eventtype == "SPELL_MISSED" or eventtype == "SPELL_HEAL_ABSORBED") then
		local spellID, spellName, spellSchool, aSrcGUID, aSrcName, _, _, aSpellID, aSpellName, aSpellSchool, aSpellAmountAbsorbed, somebullshit, horseshit =
			...
		local function debuggerprinter()
			if aura_env.debug then
				local str = string.format(
					"event: %s, timestamp: %s, eventtype: %s, hideCaster: %s, srcGUID: %s, srcName: %s, dstGUID: %s, dstName: %s, spellID: %s, spellName: %s, spellSchool: %s, aSpellAmountAbsorbed: %s, somebullshit: %s, horseshit: %s",
					tostring(event),
					tostring(timestamp),
					tostring(eventtype),
					tostring(hideCaster),
					tostring(srcGUID),
					tostring(srcName),
					tostring(dstGUID),
					tostring(dstName),
					tostring(spellID),
					tostring(spellName),
					tostring(spellSchool),
					tostring(aSpellAmountAbsorbed),
					tostring(somebullshit),
					tostring(horseshit)
				)
				print(str)
			end
		end
		debuggerprinter()
		-- Ray absorbed heal
		-- srcName = Player
		-- dstName = RoH Target
		-- spellID = RoH spellID
		-- aSrcName = Absorbed Heal Caster
		-- aSpellID = Absorbed Heal SpellID
		-- aSpellAmountAbsorbed = duh;
		if eventtype == "SPELL_HEAL_ABSORBED" then
			-- if aura_env.debug then spellID = 197268 end
			if srcGUID == UnitGUID("player") and spellID == aura_env.spellID then
				if aura_env.debug then
					local str = string.format(
						"Ray of Hope absorbed %s's heal, %s, for %d.",
						tostring(aSrcName),
						tostring(aSpellName),
						tostring(aSpellAmountAbsorbed)
					)
					print(str)
				end

				aura_env.totalHealAbsorb = aura_env.totalHealAbsorb + aSpellAmountAbsorbed
				return true
			end
		end

		-- Ray absorbed dmg
		-- srcName = enemy
		-- dstName = RoH Target
		-- spellID = Spell Absorbed spellID
		-- spellName = Spell Absorbed Name
		-- aSrcName = Player
		-- aSpellID = RoH spellID
		if eventtype == "SPELL_ABSORBED" then
			-- if aura_env.debug then aSpellID = 197268 end
			if aSrcGUID == UnitGUID("player") and aSpellID == aura_env.spellID then
				if aura_env.debug then
					local str = string.format(
						"Ray of Hope absorbed %s's damage, %s, for %d.",
						tostring(srcName),
						tostring(spellName),
						tostring(aSpellAmountAbsorbed)
					)
					print(str)
				end

				aura_env.totalDmgAbsorb = aura_env.totalDmgAbsorb + aSpellAmountAbsorbed
				return true
			end
		end
	end

	-- Ray expire
	if aura_env.rayActive and eventtype == "SPELL_AURA_REMOVED" then
		local spellID = ...
		if srcGUID == UnitGUID("player") and spellID == aura_env.spellID then
			if aura_env.debug then
				print("Ray removed.")
				print("RoH heals taken: ", tostring(aura_env.totalHealAbsorb))
				print("RoH dmg taken: ", tostring(aura_env.totalDmgAbsorb))

				-- 1.5 represents the 50% modifier to heals into ray
				local net = aura_env.totalHealAbsorb * 1.5 - aura_env.totalDmgAbsorb

				local colorString = ""
				if net > 0 then
					colorString = string.format("|cff00ff00%d|r", net)
				else
					colorString = string.format("|cffff0000%d|r", net)
				end
				print("Net: ", colorString)
			end

			aura_env.rayActive = false
		end
	-- else
	-- 	print(string.format("Ray not active (%s) or event fucked %s", tostring(aura_env.rayActive), tostring(eventtype)))
	end
end
