#pragma once

#include "CoreMinimal.h"
#include "WingServer.h"
#include "WingHandler.h"
#include "WingFetcher.h"
#include "WingVariables.h"
#include "Variables_Remove.generated.h"


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

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

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

	UPROPERTY(meta=(Optional, Description="Blueprint variable names to remove, comma-separated"))
	FString BlueprintVariables;

	UPROPERTY(meta=(Optional, Description="Input variable names to remove, comma-separated"))
	FString InputVariables;

	UPROPERTY(meta=(Optional, Description="Output variable names to remove, comma-separated"))
	FString OutputVariables;

	UPROPERTY(meta=(Optional, Description="Local variable names to remove, comma-separated"))
	FString LocalVariables;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("Remove variables from a blueprint, graph, or custom event node."));
	}
	virtual void Handle() override
	{
		WingFetcher F;
		UObject* Obj = F.Walk(Object).Cast<UObject>();
		if (!Obj) return;

		WingVariables Vars;
		if (!Vars.SetBackingStore(Obj)) return;
		if (!Vars.BlueprintVariables.ParseNamesString(BlueprintVariables)) return;
		if (!Vars.InputVariables.ParseNamesString(InputVariables)) return;
		if (!Vars.OutputVariables.ParseNamesString(OutputVariables)) return;
		if (!Vars.LocalVariables.ParseNamesString(LocalVariables)) return;
		if (!Vars.Remove()) return;
		UWingServer::Printf(TEXT("Success.\n"));
	}
};
