#pragma once

#include "CoreMinimal.h"
#include "WingServer.h"
#include "WingHandler.h"
#include "WingFetcher.h"
#include "WingProperty.h"
#include "WingUtils.h"
#include "Details_Get.generated.h"

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

public:
	UPROPERTY(EditAnywhere, meta=(Description="Target object"))
	FString Object;

	UPROPERTY(EditAnywhere, meta=(Description="Property name"))
	FString Property;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("Get the value of a single property."));
	}

	virtual void Handle() override
	{
		WingFetcher F;
		UObject* Obj = F.Walk(Object).Cast<UObject>();
		if (!Obj) return;

		TArray<FWingProperty> Props = FWingProperty::GetDetailsImmutable(Obj, CPF_Edit);
		FWingProperty* P = WingUtils::FindOneWithExternalID(Property, Props, TEXT("Property"));
		if (!P) return;

		UWingServer::Print(P->GetText());
	}
};
