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

#include "Decorators/ComboActionDecoratorBase.h"

#if WITH_EDITOR
#include "Editor.h"
#endif

DEFINE_LOG_CATEGORY(LogComboActionDecoratorBase);

#define LOCTEXT_NAMESPACE "ComboActionDecoratorBase"


bool UComboActionDecoratorBase::ValidateDecorator_Implementation(TArray<FText>& ValidationMessages)
{
	bool bSatisfied = true;
	const FText Name = FText::FromString(GetName());

	// This is to ensure we are not throwing InvalidWorld errors in Editor with no Gameplay.
	bool bIsEditorCall = false;
#if WITH_EDITOR
	if (GEditor != nullptr)
	{
		bIsEditorCall = !GEditor->GetPlayInEditorSessionInfo().IsSet();
	}
#endif
	
	if (GetOwningWorld() == nullptr && bIsEditorCall == false)
	{
		const FText TempText = FText::Format(LOCTEXT("ComboActionDecorator_Base_Validation_World", "[{0}]: No valid World!"), Name);
		ValidationMessages.Add(TempText);

		bSatisfied = false;
	}

	if (DecoratorState == EComboActionDecoratorState::Uninitialized && bIsEditorCall == false)
	{
		const FText TempText = FText::Format(LOCTEXT("ComboActionDecorator_Base_Validation_State", "[{0}]: Not Initialized properly!"), Name);
		ValidationMessages.Add(TempText);

		bSatisfied = false;
	}
	
	if (GetOwner() == nullptr)
	{
		const FText TempText = FText::Format(LOCTEXT("ComboActionDecorator_Base_Validation_Owner", "[{0}]: No valid Owner!"), Name);
		ValidationMessages.Add(TempText);

		bSatisfied = false;
	}
		
	return bSatisfied;
}

#undef LOCTEXT_NAMESPACE
