#pragma once

#include "CoreMinimal.h"
#include "WingServer.h"
#include "WingBasics.h"
#include "WingFetcher.h"
#include "WingUtils.h"
#include "EdGraph/EdGraphNode.h"
#include "GraphNode_SetComment.generated.h"


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------

UCLASS()
class UWing_GraphNode_SetComment : public UWingHandler
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, meta=(Description="Target node"))
	FString NodePath;

	UPROPERTY(EditAnywhere, meta=(Description="Comment text to set"))
	FString Comment;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("Set a node's comment text, and make the comment visible. "
			"Setting empty text will cause the comment to vanish."));
	}
	virtual void Handle() override
	{
		WingFetcher F(WingOut::Stdout);
		UEdGraphNode* FoundNode = F.Walk(NodePath).Cast<UEdGraphNode>();
		if (!FoundNode) return;

		FoundNode->NodeComment = Comment;
		FoundNode->bCommentBubbleVisible = !Comment.IsEmpty();
		FoundNode->bCommentBubblePinned = !Comment.IsEmpty();

		WingOut::Stdout.Printf(TEXT("Comment set on %s\n"), *WingUtils::FormatName(FoundNode));
	}
};
