#pragma once

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


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

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

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

	UPROPERTY(EditAnywhere, meta=(Description="New name for the node"))
	FString Name;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("Rename a graph node. Works on custom events, timelines, "
			"composite nodes, comment nodes, and other renameable node types."));
	}
	virtual void Handle() override
	{
		WingFetcher F(WingOut::Stdout);
		UEdGraphNode* FoundNode = F.Walk(NodePath).Cast<UEdGraphNode>();
		if (!FoundNode) return;

		if (!WingUtils::CheckCanRename(FoundNode, Name, WingOut::Stdout)) return;
		FoundNode->OnRenameNode(Name);

		WingOut::Stdout.Printf(TEXT("Renamed node to %s\n"), *Name);
	}
};
