#pragma once

#include "CoreMinimal.h"
#include "BhvrFlowNode.h"
#include "BhvrFlowOutputDelegate.h"
#include "BhvrOverlapMonitorDelegate.h"
#include "Engine/HitResult.h"
#include "BhvrFlowNode_OverlapsMonitor.generated.h"

class AActor;
class UShapeComponent;
class UPrimitiveComponent;

UCLASS(Blueprintable)
class BHVRFLOW_API UBhvrFlowNode_OverlapsMonitor : public UBhvrFlowNode
{
	GENERATED_BODY()

public:
	UPROPERTY(BlueprintReadWrite, BlueprintAssignable)
	FBhvrFlowOutputDelegate Then;

	UPROPERTY(BlueprintReadWrite, BlueprintAssignable)
	FBhvrOverlapMonitorDelegate BeginOverlap;

	UPROPERTY(BlueprintReadWrite, BlueprintAssignable)
	FBhvrOverlapMonitorDelegate EndOverlap;

private:
	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	AActor* Owner;

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, Instanced, meta=(AllowPrivateAccess=true))
	TArray<UShapeComponent*> TriggerComponents;

public:
	UFUNCTION(BlueprintCallable)
	void StopMonitoring(bool bTriggerEndOverlap);

	UFUNCTION(BlueprintCallable)
	void StartMonitoring(AActor* InOwner, FName TriggerComponentTag, bool bMonitorOnlyOnAuthority);

private:
	UFUNCTION(BlueprintCallable)
	void OnEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

	UFUNCTION()
	void OnBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

public:
	UBhvrFlowNode_OverlapsMonitor();
};

FORCEINLINE uint32 GetTypeHash(const UBhvrFlowNode_OverlapsMonitor) { return 0; }
