#pragma once

#include "CoreMinimal.h"
#include "WingBasics.h"
#include "WingServer.h"
#include "WingFetcher.h"
#include "WingVariables.h"
#include "Variables_Dump.generated.h"


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

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

public:
	UPROPERTY(EditAnywhere, meta=(Description="Path to a blueprint, graph, or custom event node"))
	FString ObjectPath;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("List all variables of a blueprint, function graph,"
			"macro graph, event dispatcher graph, or custom event node"));
	}
	virtual void Handle() override
	{
		WingFetcher F(WingOut::Stdout);
		UObject* Obj = F.Walk(ObjectPath).Cast<UObject>();
		if (!Obj) return;

		WingVariables Vars;
		if (!Vars.SetBackingStore(Obj, WingOut::Stdout)) return;
		Vars.Load(WingOut::Stdout);
		Vars.Print(WingOut::StdoutBuffer);
	}
};
