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

#pragma once
#include "CoreMinimal.h"
#if WITH_EDITOR
#if PLATFORM_WINDOWS
THIRD_PARTY_INCLUDES_START
#include "Windows\AllowWindowsPlatformTypes.h"
#include "Simplygon.h"
#include "Windows\HideWindowsPlatformTypes.h"
THIRD_PARTY_INCLUDES_END
#endif // PLATFORM_WINDOWS
#endif
#include "Misc/ScopedSlowTask.h"

class FDefaultEventHandler : public Simplygon::Observer
{
public:
	const FSimplygonJobData& JobData;
	const FSimplygonProcessProgressDelegate& ProgressDelegate;
	int32 PreviousProgress;

	FDefaultEventHandler(const FSimplygonJobData& InJobData, const FSimplygonProcessProgressDelegate& InProgressDelegate)
		: JobData(InJobData)
		, ProgressDelegate(InProgressDelegate)
		, PreviousProgress(0)
	{
	}

	virtual bool OnProgress(
		Simplygon::spObject Object,
		float progressPercent) override
	{
		float ProgressPercent = FMath::Clamp(progressPercent, 0.0f, 100.0f);
		if (ProgressPercent > PreviousProgress)
		{
			int32 ProgressDelta = ProgressPercent - PreviousProgress;
			ProgressDelegate.ExecuteIfBound(JobData, ProgressPercent, ProgressDelta);
			PreviousProgress = ProgressPercent;
		}
		return true;
	}
};
