#pragma once

#include "CoreMinimal.h"
#include "WingServer.h"
#include "WingBasics.h"
#include "WingFetcher.h"
#include "WingUtils.h"
#include "Engine/Blueprint.h"
#include "Kismet2/BlueprintEditorUtils.h"
#include "BlueprintOverride_ShowMenu.generated.h"


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

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

public:
	UPROPERTY(EditAnywhere, meta=(Description="Blueprint path"))
	FString BlueprintPath;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("Show the functions that can be overridden in a Blueprint."));
	}

	virtual void Handle() override
	{
		WingFetcher F(WingOut::Stdout);
		UBlueprint* BP = F.Walk(BlueprintPath).Cast<UBlueprint>();
		if (!BP) return;

		TArray<UFunction*> Results = WingUtils::GetOverridableFunctions(BP);
		for (UFunction *Func : Results)
		{
			UClass *Class = WingUtils::GetFunctionClass(Func);
			WingOut::Stdout.Print(WingUtils::GetFunctionMenuString(Func));
			WingOut::Stdout.Print(TEXT("\n"));
		}
		if (Results.IsEmpty())
			WingOut::Stdout.Print(TEXT("No overridable functions.\n"));
	}
};
