#pragma once

#include "CoreMinimal.h"
#include "Extensions/DruidsMCPBridgeSageExtension.h"
#include "UObject/Object.h"
#include "DruidsMCPBridgeSageExtensionRegistry.generated.h"

UCLASS()
class UDruidsMCPBridgeSageExtensionRegistry : public UObject
{
	GENERATED_BODY()

public:
	static UDruidsMCPBridgeSageExtensionRegistry* Get();
	static void Shutdown();

	void Reset();
	void Refresh();

	TArray<TWeakObjectPtr<UDruidsMCPBridgeSageExtension>> GetActiveExtensions();
	TArray<TSharedPtr<FDruidsMCPBridgeSageExtensionDefinition>> GetAllExtensionDefinitions();
	TWeakObjectPtr<UDruidsMCPBridgeSageExtension> GetExtensionForId(const FString& ExtensionId);

private:
	void DiscoverNativeExtensions();
	void DiscoverBlueprintExtensions();
	void RegisterExtension(UDruidsMCPBridgeSageExtension* Extension);

	UPROPERTY()
	TMap<FString, TObjectPtr<UDruidsMCPBridgeSageExtension>> RegisteredExtensions;

	mutable FCriticalSection ExtensionsLock;
};
