#pragma once

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

class AHyperTwistVirtual3333ProjectionActor;
class UCameraComponent;
class USceneComponent;
class USpringArmComponent;

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

public:
	AHyperTwistVirtual3333ProjectionOrbitPawn();

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

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

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Virtual3333|Camera")
	bool bFollowActiveProjectionActor = true;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

protected:
	void ApplyOrbitTransform();
	void RefreshOrbitFocusPointFromProjection();
	AHyperTwistVirtual3333ProjectionActor* ResolveProjectionActor() const;
	bool ShouldOrbitFromMouseInput() const;

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