#pragma once

#include "CoreMinimal.h"
#include "Perk.h"
#include "Templates/SubclassOf.h"
#include "PerformancePerk.generated.h"

class UPerformanceInteraction;
class APerformanceTrackManager;
class UInteractionAttacherComponent;
class UBaseLingeringStatusEffect;
class UChargeableComponent;
class ADBDPlayer;

UCLASS(Blueprintable, Abstract, meta=(BlueprintSpawnableComponent))
class DBDCOMPETENCE_API UPerformancePerk : public UPerk
{
	GENERATED_BODY()

protected:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float _performanceRange;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TSubclassOf<UPerformanceInteraction> _performanceInteraction;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float _performanceInteractionDuration;

	UPROPERTY(EditAnywhere)
	float _cooldownDuration;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, ReplicatedUsing=OnRep_TrackSelectionManager)
	APerformanceTrackManager* _trackSelectionManager;

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, ReplicatedUsing=OnRep_InteractionAttacherComponent, Transient, Instanced)
	UInteractionAttacherComponent* _interactionAttacherComponent;

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, Instanced)
	TArray<UBaseLingeringStatusEffect*> _spawnedStatusEffects;

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, Instanced)
	UPerformanceInteraction* _interaction;

	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, Instanced)
	UChargeableComponent* _performanceChargeableComponent;

protected:
	UFUNCTION(BlueprintCallable)
	void OnRep_TrackSelectionManager();

	UFUNCTION(BlueprintCallable)
	void OnRep_InteractionAttacherComponent();

	UFUNCTION(BlueprintCallable)
	void OnInteractionEntered(ADBDPlayer* player);

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

protected:
	UFUNCTION(BlueprintCallable)
	void Authority_RemoveStatusEffects();

	UFUNCTION(BlueprintCallable)
	void Authority_OnInteractionStarted();

	UFUNCTION(BlueprintCallable)
	void Authority_OnInteractionDone();

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

public:
	UPerformancePerk();
};

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