#pragma once

#include "CoreMinimal.h"
#include "BhvrTickableFlowNode.h"
#include "PawnObserverDelegate.h"
#include "BhvrFlowNode_PawnObserver.generated.h"

class APawn;
class AActor;
class APlayerState;

UCLASS(Blueprintable)
class BHVRFLOW_API UBhvrFlowNode_PawnObserver : public UBhvrTickableFlowNode
{
	GENERATED_BODY()

public:
	UPROPERTY(BlueprintReadWrite, BlueprintAssignable)
	FPawnObserverDelegate PawnChanged;

protected:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	APawn* CurrentPawn;

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

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	APawn* OldPawn;

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	bool IsWaitingForPawnReady;

public:
	UFUNCTION(BlueprintCallable)
	void Stop();

	UFUNCTION(BlueprintCallable)
	void Start(AActor* Actor);

private:
	UFUNCTION(BlueprintCallable)
	void OnPawnChanged_PlayerState(APlayerState* InPlayerState, APawn* InNewPawn, APawn* InOldPawn);

	UFUNCTION(BlueprintCallable)
	void OnPawnChanged_PlayerController(APawn* InOldPawn, APawn* InNewPawn);

protected:
	UFUNCTION(BlueprintPure, BlueprintImplementableEvent)
	bool BP_ValidatePawn() const;

public:
	UBhvrFlowNode_PawnObserver();
};

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