#include "ScriptMgr.h"
#include "Player.h"
#include "chat.h"

class Duel_Reset : public PlayerScript
{
public:
	Duel_Reset() : PlayerScript("Duel_Reset"){}
	bool UsingPreDuelInfo = false; // CHange this to false if you want a full reset.

	struct MyData
	{
		uint64 resethealth;
		uint64 resetPower;
		uint64 resetEnergy;
		uint64 resetRage;
	};

	std::unordered_map<ObjectGuid, MyData> playerData;
	/*void GetInfoPreDuel(Player* playerwin, Player* playerlose)
	{
		playerData[playerwin->GetGUID()].resethealth = playerwin->GetHealth();
		playerData[playerwin->GetGUID()].resetPower = playerwin->GetPower(playerwin->getPowerType());
		playerData[playerlose->GetGUID()].resethealth = playerlose->GetHealth();
		playerData[playerlose->GetGUID()].resetPower = playerlose->GetPower(playerlose->getPowerType());

	}
	void DoFullReset(Player* playerwin, Player* playerlose)
	{
		playerData[playerwin->GetGUID()].resethealth = playerwin->GetMaxHealth();
		playerData[playerwin->GetGUID()].resetPower = playerwin->GetMaxPower(playerlose->getPowerType());
		playerData[playerlose->GetGUID()].resethealth = playerlose->GetMaxHealth();
		playerData[playerlose->GetGUID()].resetPower = playerlose->GetMaxPower(playerwin->getPowerType());
	}

	void OnDuelStart(Player* playerwin, Player* playerlose)
	{
		if (!UsingPreDuelInfo)
		{
			DoFullReset(playerwin, playerlose);
		}
		if (UsingPreDuelInfo)
		{
			GetInfoPreDuel(playerwin, playerlose);
		}
	}*/

	void OnDuelEnd(Player* playerwin, Player* playerlose, DuelCompleteType /*type*/)
	{
		playerwin->SetHealth(playerwin->GetMaxHealth());
		playerwin->SetPower(playerwin->getPowerType(), playerwin->GetMaxPower(playerwin->getPowerType()));
		playerlose->SetHealth(playerlose->GetMaxHealth());
		playerlose->SetPower(playerlose->getPowerType(), playerlose->GetMaxPower(playerlose->getPowerType()));

		if (!UsingPreDuelInfo)
		{
			//playerwin->GetSession()->SendAreaTriggerMessage("Your Health & Mana has been reset.");
			//playerlose->GetSession()->SendAreaTriggerMessage("Your Health & Mana has been reset.");
			playerwin->GetSpellHistory()->ResetAllCooldowns();
			playerlose->GetSpellHistory()->ResetAllCooldowns();
		}
		else
		{
			//playerwin->GetSession()->SendAreaTriggerMessage("Your Health & Mana has been reset to what they were before the duel!");
			//playerlose->GetSession()->SendAreaTriggerMessage("Your Health & Mana has been reset to what they were before the duel!");
		}
		playerData.erase(playerwin->GetGUID());
		playerData.erase(playerlose->GetGUID());
	}
};

void AddSC_Duel_Reset()
{
	new Duel_Reset;
}