#pragma once

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

class AHyperTwistMelindaProjectionActor;
class UCameraComponent;
class USceneComponent;
class USpringArmComponent;

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

public:
	AHyperTwistMelindaProjectionOrbitPawn();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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