#pragma once

#include "CoreMinimal.h"
#include "Factories/EnumFactory.h"
#include "WingBasics.h"
#include "WingFactories.generated.h"

class UFactory;

class WingFactories
{
public:
	// Create an asset on disk, using a factory instance.
	// Returns the main object. If there are problems,
	// prints error messages and returns nullptr.  If
	// CheckIs is nonnull, this does a final check to verify
	// that the created asset is a child of the specified
	// class.
	static UObject *CreateAsset(
		const FString &Path, UFactory *Factory, UClass *CheckIs, WingOut Errors);

	// Some factories are blacklisted, mainly because they
	// pop up dialog boxes. In those cases, we deal with it
	// primarily by adding those factories to the blacklist,
	// and then implementing replacement factories.
	static bool IsBlacklisted(TSubclassOf<UFactory> FactoryClass);

	// Some factories require special-case attention.  These
	// factories are valid factories that can be used by handlers,
	// and are not blacklisted.  However, they should not be
	// auto-registered by handlers that do bulk registration
	// of large numbers of factories.
	static bool IsSpecialCase(TSubclassOf<UFactory> FactoryClass);

	// Check if the factory class can be used to create assets.
	// makes sure it's not abstract, checks CanCreateNew,
	// checks ShouldShowInNewMenu, and verifies not blacklisted.
	static bool CanCreate(TSubclassOf<UFactory> FactoryClass);

	// Get the names of the editable properties for a factory class.
	static TArray<FName> GetParameterNames(TSubclassOf<UFactory> FactoryClass);

	// This takes a factory name and turns it into a string
	// that we can present to the user.  Mainly, it removes
	// the word 'Factory', and anything that comes after.
	static FString DeriveFactoryName(TSubclassOf<UFactory> FactoryClass);

	// Verifies that the asset path is a valid path, and also
	// that there's not something already there at that path.
	static bool CheckNewAssetPath(const FString &Path, WingOut Errors);
};

// The original UEnumFactory may pop a dialog.  We made a better one.
UCLASS()
class UEnumFactoryWing : public UEnumFactory
{
	GENERATED_BODY()
public:
	virtual UObject* FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) override;
};
