-- ==================================================================================================================== --
--															--
--	File			AvoidableDamageTaken.lua ( modification of DamageTaken.lua )				--
--															--
--															--
--	Author			Zarnivoop						| Basis, thx	|		--
--															--
--										| Version	   :	 12.0.1 |	--
--										| Curse-Project-ID :	  17718 |	--
--										| Wago-ID	   :   Q6aEVa6W |	--
--										| License	   :	  MIT/X |	--
--															--
--															--
--				Baltha							| Revision	|		--
--										| Version	   :	 12.0.1 |	--
--										| Curse-Project-ID :	1188318 |	--
--										| License	   :	  MIT/X |	--
--															--
--															--
--										| Initial Version  : 2024-11-18 |	--
--										| Current Version  : 2026-04-22 |	--
--										|		   : Release	|	--
--															--
--															--
--	Path ( Revision )	"..\World of Warcraft\_retail_\Interface\AddOns\Skada\Misc\Changelog\ChangeLog.txt"	--
--															--
-- ==================================================================================================================== --


local _, Skada	   = ...


local ModuleBase   = Skada.ModuleBase
local SecretHelper = Skada.SecretHelper


-- ==========================
-- | outer function : start |
-- ==========================
Skada:AddLoadableModule("AvoidableDamageTaken", nil, function(Skada, L)

	if Skada.db.profile.modulesBlocked.AvoidableDamageTaken then return end


	local mod = Skada:NewModule(L["Avoidable damage taken"])
	local playermod = Skada:NewModule(L["Avoidable damage taken details"])


	-- ===============================================================================
	-- | e.g. https://warcraft.wiki.gg/wiki/API_C_DamageMeter.GetCombatSessionFromID |
	-- |										 |
	-- | Enum.DamageMeterType							 |
	-- |										 |
	-- |		Value	8							 |
	-- |		Field	AvoidableDamageTaken					 |
	-- ===============================================================================
	local DAMAGE_TYPE = 8


	function playermod:Enter(win, id, label)

		playermod.playerid = id
		playermod.title	   = tostring(label) .. L["'s Avoidable damage taken"]
	end




	function playermod:Update(win, set)

		ModuleBase:UpdateSpellList(win, self.playerid, set, DAMAGE_TYPE)
	end




	function mod:Update(win, set)

		ModuleBase:UpdatePlayerList(win, set,

							{

								     damageType = DAMAGE_TYPE								,
								       valueKey = "totalAmount"								,
								        rateKey = "amountPerSecond"							,
								        columns = {"Damage", "DTPS", "Percent"}						,
								    getRateFunc = function(s, p)

											  return ModuleBase:GetPlayerRate(s, p, DAMAGE_TYPE)
										  end									,
								     formatRate = function(rate)

											  return string.format("%02.1f", rate)
										  end									,
								 includePercent = true

							}

					   )

	end




	function mod:OnEnable()

		playermod.metadata = {}
		mod.metadata	   = {click1 = playermod, showspots = true, columns = {Damage = true, DTPS = true, Percent = true}, icon = "Interface\\Icons\\Inv_shield_06"}


		Skada:AddMode(self)
	end




	function mod:OnDisable()

		Skada:RemoveMode(self)
	end




	function mod:FormatSetSummary(datasetItem, set)

		ModuleBase:FormatSetSummary(datasetItem, set,

								{
								     damageType = DAMAGE_TYPE			,
									    Key = "totalAmount"			,
									   Type = DAMAGE_TYPE			,
									columns = {"Damage", "DTPS"}
								}

					   )
	end

end)
-- ========================
-- | outer function : end |
-- ========================