// ©2023 Batty Bovine Productions, LLC. All Rights Reserved.

#include "Data/ComboActionContext.h"

#include "Interfaces/ComboActionInterface.h"


bool UComboActionContext::IsValid() const
{
	return ActiveNode != nullptr;// && DialogueParticipant.GetInterface() != nullptr && PlayerDialogueParticipant.GetInterface() != nullptr;
}

void UComboActionContext::SetComboActionContext(UComboActionGraphNode *NewActiveNode, const TArray<UComboActionGraphNode*> NewAllowedChildNodes)
{
	//DialogueParticipant = NewParticipant;
	//ActiveNode = NewActiveNode;
	//AllowedChildNodes = NewAllowedChildNodes;

	//if (!DialogueParticipants.Contains(NewParticipant))
	//{
	//	DialogueParticipants.Add(NewParticipant);
	//}
}

//void UComboActionContext::UpdateDialogueParticipant(const TScriptInterface<IComboActionParticipantInterface> NewParticipant)
//{
//	DialogueParticipant = NewParticipant;
//
//	AddDialogueParticipant(NewParticipant);
//}
//
//void UComboActionContext::UpdateActiveDialogueNode(UComboActionGraphNode *NewActiveNode)
//{
//	ActiveNode = NewActiveNode;
//}
//
//void UComboActionContext::UpdateAllowedChildrenNodes(const TArray<UComboActionGraphNode*> &NewNodes)
//{
//	AllowedChildNodes = NewNodes;
//}
//
//void UComboActionContext::UpdateActiveDialogueRowDataIndex(const int32 NewIndex)
//{
//	ActiveDialogueRowDataIndex = NewIndex;
//}
//
//void UComboActionContext::UpdateDialoguePlayerParticipant(const TScriptInterface<IComboActionParticipantInterface> NewParticipant)
//{
//	PlayerDialogueParticipant = NewParticipant;
//	
//	AddDialogueParticipant(NewParticipant);
//}
//
//void UComboActionContext::UpdateActiveDialogueParticipant(const TScriptInterface<IComboActionParticipantInterface> NewParticipant)
//{
//	if (NewParticipant != PlayerDialogueParticipant && NewParticipant != DialogueParticipant)
//	{
//		//TODO: Properly log this
//		return;
//	}
//
//	ActiveDialogueParticipant = NewParticipant;
//}
//
//void UComboActionContext::AddTraversedNode(const UComboActionGraphNode *TraversedNode)
//{
//	if (!TraversedNode) return;
//	
//	// If we have already passed over this Node, then just increase the counter
//	if (TraversedPath.Contains(TraversedNode->GetNodeGUID()))
//	{
//		TraversedPath[TraversedNode->GetNodeGUID()]++;
//	}
//	else
//	{
//		TraversedPath.Add(TraversedNode->GetNodeGUID(), 1);
//	}
//}
//
//bool UComboActionContext::AddDialogueParticipants(const TArray<TScriptInterface<IComboActionParticipantInterface>>& NewParticipants)
//{
//	bool bSatisfied = true;
//	for (const auto& Itr : NewParticipants)
//	{
//		const bool bTempSatisfied = AddDialogueParticipant(Itr);
//		bSatisfied = bTempSatisfied ? bSatisfied : bTempSatisfied;
//	}
//
//	return bSatisfied;
//}
//
//bool UComboActionContext::AddDialogueParticipant(const TScriptInterface<IComboActionParticipantInterface>& NewParticipant)
//{
//	if (DialogueParticipants.Contains(NewParticipant))
//	{
//		return false;
//	}
//
//	DialogueParticipants.Add(NewParticipant);
//	return true;
//}
//
//bool UComboActionContext::RemoveDialogueParticipants(const TArray<TScriptInterface<IComboActionParticipantInterface>>& NewParticipants)
//{
//	bool bSatisfied = true;
//	for (const auto& Itr : NewParticipants)
//	{
//		const bool bTempSatisfied = RemoveDialogueParticipant(Itr);
//		bSatisfied = bTempSatisfied ? bSatisfied : bTempSatisfied;
//	}
//
//	return bSatisfied;
//}
//
//bool UComboActionContext::RemoveDialogueParticipant(const TScriptInterface<IComboActionParticipantInterface>& NewParticipant)
//{
//	if (DialogueParticipants.Contains(NewParticipant))
//	{
//		DialogueParticipants.Remove(NewParticipant);
//		return true;
//	}
//
//	return false;
//}
//
//void UComboActionContext::ClearDialogueParticipants()
//{
//	DialogueParticipants.Empty();
//}

void UComboActionContext::SetComboActionContextBP(UComboActionGraphNode *NewActiveNode,TArray<UComboActionGraphNode*> NewAllowedChildNodes)
{
	//this->SetComboActionContext(NewParticipant, NewActiveNode, NewAllowedChildNodes);

	ComboActionContextUpdatedFromBlueprint.Broadcast(this);
}

//void UComboActionContext::UpdateDialogueParticipantBP(const TScriptInterface<IComboActionParticipantInterface> NewParticipant)
//{
//	UpdateDialogueParticipant(NewParticipant);
//	
//	DialogueContextUpdatedFromBlueprint.Broadcast(this);
//}
//
//void UComboActionContext::UpdateActiveDialogueNodeBP(UComboActionGraphNode *NewActiveNode)
//{
//	UpdateActiveDialogueNode(NewActiveNode);
//
//	DialogueContextUpdatedFromBlueprint.Broadcast(this);
//}
//
//void UComboActionContext::UpdateActiveDialogueRowBP(const FDialogueRow &NewActiveRow)
//{
//	UpdateActiveDialogueRow(NewActiveRow);
//	
//	DialogueContextUpdatedFromBlueprint.Broadcast(this);
//}
//
//void UComboActionContext::UpdateActiveDialogueRowDataIndexBP(const int32 NewIndex)
//{
//	UpdateActiveDialogueRowDataIndex(NewIndex);
//
//	DialogueContextUpdatedFromBlueprint.Broadcast(this);
//}
//
//void UComboActionContext::UpdateDialoguePlayerParticipantBP(const TScriptInterface<IComboActionParticipantInterface> NewParticipant)
//{
//	UpdateDialoguePlayerParticipant(NewParticipant);
//
//	DialogueContextUpdatedFromBlueprint.Broadcast(this);
//}
//
//void UComboActionContext::UpdateActiveDialogueParticipantBP(const TScriptInterface<IComboActionParticipantInterface> NewParticipant)
//{
//	UpdateActiveDialogueParticipant(NewParticipant);
//
//	DialogueContextUpdatedFromBlueprint.Broadcast(this);
//}
//
//bool UComboActionContext::AddDialogueParticipantBP(const TScriptInterface<IComboActionParticipantInterface> &NewParticipant)
//{
//	if (AddDialogueParticipant(NewParticipant))
//	{
//		DialogueContextUpdatedFromBlueprint.Broadcast(this);
//		return true;
//	}
//
//	return false;
//}
//
//bool UComboActionContext::RemoveDialogueParticipantBP(const TScriptInterface<IComboActionParticipantInterface> &NewParticipant)
//{
//	if (RemoveDialogueParticipant(NewParticipant))
//	{
//		DialogueContextUpdatedFromBlueprint.Broadcast(this);
//		return true;
//	}
//
//	return false;
//}
//
//bool UComboActionContext::AddDialogueParticipantsBP(const TArray<TScriptInterface<IComboActionParticipantInterface>> &NewParticipants)
//{
//	if (AddDialogueParticipants(NewParticipants))
//	{
//		DialogueContextUpdatedFromBlueprint.Broadcast(this);
//		return true;
//	}
//
//	return false;
//}
//
//bool UComboActionContext::RemoveDialogueParticipantsBP(const TArray<TScriptInterface<IComboActionParticipantInterface>> &NewParticipants)
//{
//	if (RemoveDialogueParticipants(NewParticipants))
//	{
//		DialogueContextUpdatedFromBlueprint.Broadcast(this);
//		return true;
//	}
//
//	return false;
//}
