#pragma once

#include "CoreMinimal.h"
#include "WingHandler.h"
#include "WingServer.h"
#include "WingFetcher.h"
#include "WingUtils.h"
#include "WingGraphExport.h"
#include "Engine/Blueprint.h"
#include "EdGraph/EdGraph.h"
#include "Materials/Material.h"
#include "MaterialGraph/MaterialGraph.h"
#include "Graph_Dump.generated.h"


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

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

public:
	UPROPERTY(EditAnywhere, meta=(Description="Path to graph"))
	FString Graph;

	UPROPERTY(meta=(Optional, Description="True to include less-significant details"))
	bool IncludeDetails;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("Dump blueprint or material graphs as readable text. "));
	}
	virtual void Handle() override
	{
		WingFetcher F;
		UEdGraph *G = F.Walk(Graph).Cast<UEdGraph>();
		if (!G) return;
		
		WingGraphExport Exporter(G);
		UWingServer::Print(*Exporter.GetOutput());
		if (IncludeDetails)
		{
			UWingServer::Print(Exporter.GetDetails());
		}
		else
		{
			UWingServer::Printf(TEXT("\nNote: use bDetails=true to see suppressed details."));
		}
	}
};
