#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Debug/PulseDebugSnapshot.h"
#include "MyScoreComponent.generated.h"

/** Counts a score and shows it in the Pulse Debugger. */
UCLASS(ClassGroup = (MyGame), meta = (BlueprintSpawnableComponent))
class MYGAME_API UMyScoreComponent : public UActorComponent, public IPulseDebugSnapshotProvider
{
	GENERATED_BODY()

public:

	/** Adds points to the score and records a timeline event. */
	UFUNCTION(BlueprintCallable, Category = "MyGame")
	void AddScore(int32 InPoints);

	// IPulseDebugSnapshotProvider
	virtual void GatherDebugSnapshot(FPulseDebugSnapshot& OutSnapshot) const override;
	virtual FName GetDebugCategory() const override { return TEXT("MyGame"); }
	virtual const AActor* GetDebugOwner() const override { return GetOwner(); }

protected:

	virtual void BeginPlay() override;
	virtual void EndPlay(const EEndPlayReason::Type InReason) override;

private:

	/** Gives the player some points so there is something to see. */
	void AwardPoints();

	/** Points given by every award. */
	UPROPERTY(EditAnywhere, Category = "MyGame")
	int32 PointsPerAward = 10;

	/** Seconds between two awards. */
	UPROPERTY(EditAnywhere, Category = "MyGame")
	float AwardInterval = 2.f;

	int32 Score = 0;

	FTimerHandle AwardTimer;
};
