#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "GameFramework/Pawn.h"

#include "HeadMountedDisplay.h"
#include "XRVisualizationFunctionLibrary.h"
#include "Components/PoseableMeshComponent.h"

#include "IHandsAdapter.h"

#include "OpenXrHandsAdapter.generated.h"

UCLASS()
class AR51SDK_OPENXR_API AOpenXrHandsAdapter : public APawn, public IHandsAdapter
{
	GENERATED_BODY()

private:

	UPoseableMeshComponent* _leftHand;
	UPoseableMeshComponent* _rightHand;
	TArray<EHandKeypoint> _boneTypes;
	FXRMotionControllerData _LHandMotionControllerData;
	FXRMotionControllerData _RHandMotionControllerData;

	static const TArray<FName>& GetBoneNames();
	static const TArray<EHandKeypoint>& GetBoneTypes();

	TArray<HandJointInfo> GetJointInfos(EHandType handType);
	bool RenderHands(bool isRightHand);
	void ApplyMotionDataToMesh(const FXRMotionControllerData& MotionData, bool isRightHand);

	
public:	

	UPROPERTY()
		TArray<FTransform> HandJointTransforms;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="General")
	bool ShowHands { false };

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "General", meta = (ToolTip = "Hand below this value (in cm) are assumed to be caused by some sensor error and will not be captured."))
		float ValidHandMinimumPalmSize{ 3.5f };

	// Sets default values for this actor's properties
	AOpenXrHandsAdapter();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;


	// Inherited via IHandsAdapter
	virtual FString GetSourceDevice() const override;

	virtual TArray<HandJointInfo> GetRightJointInfos() override;

	virtual TArray<HandJointInfo> GetLeftJointInfos() override;

};
