// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "HAL/ThreadSafeBool.h"
#include "Modules/ModuleManager.h"

class FEmoShapeIONative;
DECLARE_LOG_CATEGORY_EXTERN(LogEmoShape, Log, All);


class FESIONative;

class FEmoShapeSubSystemModule : public IModuleInterface
{
public:

	/** IModuleInterface implementation */
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;

	static inline FEmoShapeSubSystemModule& Get()
	{
		return FModuleManager::LoadModuleChecked< FEmoShapeSubSystemModule >("EmoShapeSubSystem");
	}
	
	TSharedPtr<FESIONative> NewValidNativePointer(const bool bShouldUseTlsLibraries = false, const bool bShouldSkipCertificateVerification = true);
	TSharedPtr<FESIONative> ValidSharedNativePointer(FString SharedId, const bool bShouldUseTlsLibraries, const bool bShouldSkipCertificateVerification);
	void ReleaseNativePointer(TSharedPtr<FESIONative> PointerToRelease);

private:

	FCriticalSection DeleteSection;

	//All native pointers manages by the plugin
	TArray<TSharedPtr<FESIONative>> PluginNativePointers;

	//Shared pointers, these will typically be alive past game world lifecycles
	TMap<FString, TSharedPtr<FESIONative>> SharedNativePointers;
	TSet<TSharedPtr<FESIONative>> AllSharedPtrs;	//reverse lookup

	FThreadSafeBool bHasActiveNativePointers;
};
