#pragma once

#include "CoreMinimal.h"
#include "WingBasics.h"
#include "WingFetcher.h"
#include "WingServer.h"
#include "WingComponent.h"
#include "ActorComponent_Remove.generated.h"


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

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

public:
	UPROPERTY(EditAnywhere, meta=(Description="Path to the component (e.g. '/Game/MyBP,component:MyComp')"))
	FString ComponentPath;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("Remove a component from a Blueprint's SimpleConstructionScript."));
	}
	virtual void Handle() override
	{
		WingFetcher F(WingOut::Stdout);
		UWingComponentRef* CompRef = F.Walk(ComponentPath).Cast<UWingComponentRef>();
		if (!CompRef) return;

		if (!UWingComponent::DeleteComponent(CompRef, WingOut::Stdout)) return;

		WingOut::Stdout.Printf(TEXT("Removed component.\n"));
	}
};
