#pragma once

#include "CoreMinimal.h"
#include "WingServer.h"
#include "WingBasics.h"
#include "WingFetcher.h"
#include "WingParameterEditor.h"
#include "Materials/MaterialInstanceConstant.h"
#include "MaterialInstance_DumpParameters.generated.h"


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

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

public:
	UPROPERTY(EditAnywhere, meta=(Description="Target material instance"))
	FString MaterialInstance;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("List all parameters on a Material Instance, showing current values and which are overridden."));
	}
	virtual void Handle() override
	{
		WingFetcher F(WingOut::Stdout);
		UMaterialInstanceConstant* MI = F.Asset(MaterialInstance).Cast<UMaterialInstanceConstant>();
		if (!MI) return;

		auto AllParams = FWingParameterEditor::GetMaterialParameters(MI);
		FWingParameterEditor::PrintAll(AllParams, true);
		if (AllParams.IsEmpty()) WingOut::Stdout.Printf(TEXT("No material parameters.\n"));
	}
};
