#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "HyperTwistReplay/HyperTwistReplayTypes.h"
#include "HyperTwistReplayReviewLibrary.generated.h"

UENUM(BlueprintType)
enum class EHyperTwistReplayReviewAnchorKind : uint8
{
	InspectionStart UMETA(DisplayName = "Inspection Start"),
	InspectionEnd UMETA(DisplayName = "Inspection End"),
	TimerStart UMETA(DisplayName = "Timer Start"),
	FirstMove UMETA(DisplayName = "First Move"),
	PhaseBoundary UMETA(DisplayName = "Phase Boundary"),
	RecognitionCommit UMETA(DisplayName = "Recognition Commit"),
	RecognitionCorrection UMETA(DisplayName = "Recognition Correction"),
	Pause UMETA(DisplayName = "Pause"),
	Resume UMETA(DisplayName = "Resume"),
	DeviceSync UMETA(DisplayName = "Device Sync"),
	StateSnapshot UMETA(DisplayName = "State Snapshot"),
	Annotation UMETA(DisplayName = "Annotation"),
	SolveEnd UMETA(DisplayName = "Solve End")
};

USTRUCT(BlueprintType)
struct FHyperTwistReplayReviewAnchor
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistReplayReviewAnchorKind AnchorKind = EHyperTwistReplayReviewAnchorKind::Annotation;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString EventId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 Sequence = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 TimeMs = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Label;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString PhaseId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString PhaseKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bMarksCompletion = false;
};

USTRUCT(BlueprintType)
struct FHyperTwistReplayReviewAnalytics
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 EventCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 TimerStartAtMs = INDEX_NONE;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 SolveEndAtMs = INDEX_NONE;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 DurationAfterTimerStartMs = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 FirstMoveAtMs = INDEX_NONE;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 LastMoveAtMs = INDEX_NONE;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 PauseCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 TotalPausedMs = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 LongestIdleGapMs = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 AverageMoveGapMs = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 UniquePhaseCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 PhaseBoundaryCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString LongestPhaseKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 LongestPhaseDurationMs = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 RecognitionPreviewCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 RecognitionCommitCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 RecognitionCorrectionCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	float AverageRecognitionConfidence = -1.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	float LowestRecognitionConfidence = -1.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	float HighestRecognitionConfidence = -1.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 DeviceSyncCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 StateSnapshotCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 AnnotationCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bHasRecognitionData = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bHasImportedSource = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistReplayReviewAnchor> ReviewAnchors;
};

UCLASS()
class UNREALHYPERTWIST_API UHyperTwistReplayReviewLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintPure, Category = "HyperTwist|Replay")
	static TArray<FHyperTwistReplayReviewAnchor> CollectReplayReviewAnchors(const FHyperTwistReplayPacket& Packet);

	UFUNCTION(BlueprintPure, Category = "HyperTwist|Replay")
	static FHyperTwistReplayReviewAnalytics DeriveReplayReviewAnalytics(const FHyperTwistReplayPacket& Packet);
};
