// Copyright (c) Microsoft Corporation. 
// Licensed under the MIT license.

#include "SimplygonPluginMeshReductionModule.h"
#include "SimplygonReduction.h"
#include "Modules/ModuleManager.h"
#include "TelemetryManager.h"
#include "Features/IModularFeatures.h"

class FSimplygonPluginMeshReductionModule : public ISimplygonPluginMeshReductionModule
{
	public:
	/** IModuleInterface implementation */
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;
	virtual ISimplygonReduction* GetSimplygonReduction() const override;

	/** IMeshReduction implementation */
	virtual class IMeshReduction* GetStaticMeshReductionInterface() override;
	virtual class IMeshReduction* GetSkeletalMeshReductionInterface() override;
	virtual class IMeshMerging* GetMeshMergingInterface() override;
	virtual class IMeshMerging* GetDistributedMeshMergingInterface() override;
	virtual FString GetName() override;
};

IMPLEMENT_MODULE( FSimplygonPluginMeshReductionModule, SimplygonPluginMeshReduction )

static TUniquePtr<ISimplygonReduction> GSimplygonMeshReduction;

ISimplygonReduction* FSimplygonPluginMeshReductionModule::GetSimplygonReduction() const
{
	return GSimplygonMeshReduction.Get();
}

void FSimplygonPluginMeshReductionModule::StartupModule()
{
	GSimplygonMeshReduction.Reset( ISimplygonReduction::Create() );
	IModularFeatures::Get().RegisterModularFeature( IMeshReductionModule::GetModularFeatureName(), this );
	FTelemetryManager::Initialize();

}

void FSimplygonPluginMeshReductionModule::ShutdownModule()
{
	IModularFeatures::Get().UnregisterModularFeature( IMeshReductionModule::GetModularFeatureName(), this );
	GSimplygonMeshReduction.Reset( nullptr );
	FTelemetryManager::Get().Shutdown();
}

IMeshReduction* FSimplygonPluginMeshReductionModule::GetStaticMeshReductionInterface()
{
	return GSimplygonMeshReduction.Get();
}

IMeshReduction* FSimplygonPluginMeshReductionModule::GetSkeletalMeshReductionInterface()
{
	return GSimplygonMeshReduction.Get();
}

IMeshMerging* FSimplygonPluginMeshReductionModule::GetMeshMergingInterface()
{
	return GSimplygonMeshReduction.Get();
}

IMeshMerging* FSimplygonPluginMeshReductionModule::GetDistributedMeshMergingInterface()
{
	return GSimplygonMeshReduction.Get();
}

FString FSimplygonPluginMeshReductionModule::GetName()
{
	return FString( "SimplygonPluginMeshReduction" );
}
