// Oleg Petruny proprietary.

#pragma once

#include "InteractableActivator.h"

#include "InCameraInteractableActivator.generated.h"

/**
 * Activates interactable only once if is in a camera view
 */
UCLASS(Blueprintable, BlueprintType, ClassGroup = InteractableActivator, meta = (BlueprintSpawnableComponent, ShortTooltip = "Activates interactable only once if is in a camera view"), MinimalAPI)
class UInCameraInteractableActivator : public UInteractableActivator
{
    GENERATED_BODY()

public:
    UInCameraInteractableActivator(const FObjectInitializer& ObjectInitializer);

protected:
    virtual void OnRegister() override;

    virtual bool AutoInstantiateInPlayer() override { return true; }

    /**
     * Scan is performed independently by _capturer member object.
     * This implementation just activates interactables in the game thread.
     */
    virtual void Scan_Implementation() override;

    /**
     * Thread safe enques interactable for activation in the next game tick
     * @param interactable .. interactable to activate
     */
    UFUNCTION(BlueprintCallable)
    void NewSeenInteractable(class AInteractable* interactable);

    /**
     * Called after interactable activation
     * @param interactable .. interactable activated
     */
    UFUNCTION(BlueprintImplementableEvent)
    void OnNewSeenInteractable(class AInteractable* interactable);

private:
    UPROPERTY()
    class UInteractableScreenCapturer* capturer;
    TQueue<class AInteractable*> interactablesToActivate;
};
