#pragma once

#include "CoreMinimal.h"
#include "BlightPowerStateInterface.h"
#include "Components/ActorComponent.h"
#include "BlightPowerCollisionDelegate.h"
#include "Templates/SubclassOf.h"
#include "DBDTunableRowHandle.h"
#include "GameplayTagContainer.h"
#include "TunableStat.h"
#include "EWallGrabState.h"
#include "BlightPowerStateComponent.generated.h"

class UBlightPowerState;
class UInteractionDefinition;
class UTimerObject;

UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent))
class UBlightPowerStateComponent : public UActorComponent, public IBlightPowerStateInterface
{
	GENERATED_BODY()

public:
	UPROPERTY(BlueprintReadWrite, BlueprintAssignable)
	FBlightPowerCollisionDelegate OnPowerCollided;

protected:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TArray<TSubclassOf<UBlightPowerState>> _blightPowerStateClasses;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FDBDTunableRowHandle _canDashCheckCollisionRadius;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FDBDTunableRowHandle _canDashCheckCollisionHeight;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FDBDTunableRowHandle _canDashCheckCollisionRange;

	UPROPERTY(EditAnywhere)
	FGameplayTagQuery _killerTagsForWallHitQuery;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FGameplayTagContainer _canWallGrabPlayerTags;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FDBDTunableRowHandle _blightLethalDashDodgeRadius;

private:
	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, Instanced, meta=(AllowPrivateAccess=true))
	UInteractionDefinition* _powerInteractionDefinition;

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, ReplicatedUsing=OnRep_StateTimer, Transient, Instanced, meta=(AllowPrivateAccess=true))
	UTimerObject* _stateTimer;

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	TArray<UBlightPowerState*> _blightPowerStates;

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	UBlightPowerState* _currentBlightPowerState;

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, ReplicatedUsing=OnRep_DashTokens, Transient, meta=(AllowPrivateAccess=true))
	uint8 _dashTokens;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(AllowPrivateAccess=true))
	FTunableStat _maximumDashTokens;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(AllowPrivateAccess=true))
	FTunableStat _tokenChargeRate;

private:
	UFUNCTION(BlueprintCallable, Server, Reliable)
	void Server_SetWallGrabState(const EWallGrabState newState);

	UFUNCTION(BlueprintCallable)
	void OnRep_StateTimer();

	UFUNCTION(BlueprintCallable)
	void OnRep_DashTokens() const;

	UFUNCTION(BlueprintCallable)
	void OnLevelReadyToPlay();

	UFUNCTION(BlueprintCallable, NetMulticast, Reliable)
	void Multicast_SetWallGrabState(const EWallGrabState newState);

public:
	UFUNCTION(BlueprintPure)
	float GetStateTimeRemaining() const;

	UFUNCTION(BlueprintPure)
	UTimerObject* GetStateTimer() const;

	UFUNCTION(BlueprintPure)
	float GetStateTimeElapsed() const;

	UFUNCTION(BlueprintPure)
	UBlightPowerState* GetPowerStateByEnum(const EWallGrabState stateEnum) const;

	UFUNCTION(BlueprintPure)
	EWallGrabState GetPowerState() const;

	UFUNCTION(BlueprintPure)
	float GetLookAngleDegrees() const;

	UFUNCTION(BlueprintPure)
	UBlightPowerState* GetCurrentPowerState() const;

	UFUNCTION(BlueprintPure)
	bool CanDash() const;

public:
	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;

public:
	UBlightPowerStateComponent();
};

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