// Oleg Petruny proprietary.

#pragma once

#include "InputActionValue.h"
#include "InteractableModificator.h"

#include "MoveInteractableModificator.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FActivateMoveInteractableModificatorActivatedDelegate);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FDeactivateMoveInteractableModificatorActivatedDelegate);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FHoldingMoveInteractableModificatorActivatedDelegate);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FRotatingMoveInteractableModificatorActivatedDelegate);

/**
 * Basic modificator for Move type activator
 */
UCLASS(Blueprintable, BlueprintType, ClassGroup = InteractableModificator, meta = (BlueprintSpawnableComponent, ShortTooltip = "Basic modificator for Move type activator"), MinimalAPI)
class UMoveInteractableModificator : public UInteractableModificator
{
    GENERATED_BODY()

public:
    UMoveInteractableModificator(const FObjectInitializer& ObjectInitializer);
    void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

    void Bind_Implementation(class UEnhancedInputComponent* input) override;
    void Unbind_Implementation() override;

    UPROPERTY(BlueprintAssignable)
    FActivateMoveInteractableModificatorActivatedDelegate OnMoveActivated;
    UPROPERTY(BlueprintAssignable)
    FDeactivateMoveInteractableModificatorActivatedDelegate OnMoveDeactivated;
    UPROPERTY(BlueprintAssignable)
    FHoldingMoveInteractableModificatorActivatedDelegate OnHolding;
    UPROPERTY(BlueprintAssignable)
    FRotatingMoveInteractableModificatorActivatedDelegate OnRotating;

protected:
    float distance = 0;
    float minDistance = 100.0f;
    float maxDistance = 200.0f;
    float zoomSpeed = 10.0f;
    float moveSpeed = 1.0f;
    float rotateSpeed = 10.0f;

private:
    void TurnOnHolding();
    void TurnOffHolding();
    void TurnOnRotating();
    void TurnOffRotating();
    void ProcessState();
    void UpdatePosition();
    void Zooming(const FInputActionValue& value);
    void Rotating(const FInputActionValue& axis);

    class UEnhancedInputComponent* lastInput = nullptr;
    TArray<int32> bindindingHandlers;
    bool holding = false;
    bool rotating = false;
    class AInteractable* actor = nullptr;
    class APlayerBase* player = nullptr;
    FCriticalSection critical;
};
