#pragma once

#include "CoreMinimal.h"
#include "WingHandler.h"
#include "WingFetcher.h"
#include "WingServer.h"
#include "WingUtils.h"
#include "WingMaterialParameter.h"
#include "MaterialTypes.h"
#include "Material_DumpParameters.generated.h"


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

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

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

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("List all parameters on a Material, showing their default values."));
	}
	virtual void Handle() override
	{
		WingFetcher F;
		UMaterial* Mat = F.Asset(Material).Cast<UMaterial>();
		if (!Mat) return;

		auto AllParams = WingMaterialParameter::GetMaterialParameters(Mat);

		for (auto& [Info, Meta] : AllParams)
		{
			WingMaterialParameter::FormatMaterialParameter(Info, Meta);
		}
		if (AllParams.IsEmpty()) UWingServer::Printf(TEXT("No material parameters.\n"));
	}
};
