#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "HyperTwistClassicCubeOrbitPawn.generated.h"

class AHyperTwistClassicCubeActor;
class UCameraComponent;
class USceneComponent;
class USpringArmComponent;

UCLASS(BlueprintType, Blueprintable)
class UNREALHYPERTWIST_API AHyperTwistClassicCubeOrbitPawn : public APawn
{
	GENERATED_BODY()

public:
	AHyperTwistClassicCubeOrbitPawn();

	virtual void BeginPlay() override;
	virtual void Tick(float DeltaSeconds) override;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	FVector OrbitFocusPoint = FVector::ZeroVector;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	bool bFollowActiveCubeActor = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	float InitialArmLength = 118.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	float MinimumArmLength = 72.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	float MaximumArmLength = 480.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	float ZoomStep = 24.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	float OrbitYawDegreesPerPixel = 0.25f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	float OrbitPitchDegreesPerPixel = 0.2f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	float MinimumPitchDegrees = -75.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	float MaximumPitchDegrees = -10.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	float InitialYawDegrees = 45.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	float InitialPitchDegrees = -28.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	bool bUseMiddleMouseOrbit = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Camera")
	bool bUseRightMouseOrbitWithShift = false;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "HyperTwist|ClassicCube|Camera")
	TObjectPtr<USceneComponent> SceneRoot = nullptr;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "HyperTwist|ClassicCube|Camera")
	TObjectPtr<USpringArmComponent> SpringArm = nullptr;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "HyperTwist|ClassicCube|Camera")
	TObjectPtr<UCameraComponent> CameraComponent = nullptr;

protected:
	void ApplyOrbitTransform();
	void RefreshOrbitFocusPointFromClassicCube();
	AHyperTwistClassicCubeActor* ResolveFocusCubeActor() const;
	bool ShouldOrbitFromMouseInput() const;

	float CurrentYawDegrees = 0.0f;
	float CurrentPitchDegrees = 0.0f;
};
