// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "AmmoSpawner.generated.h"

UCLASS()
class GAMEJAMTEMPLATE_API AAmmoSpawner : public AActor
{
	GENERATED_BODY()
	
public:
	AAmmoSpawner();

	virtual void Tick(float DeltaTime) override;

	// Function that returns the AmmoPair in the # position
	UFUNCTION(BlueprintCallable)
	class AAmmo* GetAmmoItter(int Position);

	// Function that replentishes missing ammo
	void ReplenishAmmo();

	// Function that generates missing Ammo Pair
	class AAmmo* GenerateAmmoPair(int Round, int Position);

	UFUNCTION(BlueprintCallable)
	FString ToStringAmmoPair(class AAmmo* AmmoToPrint);

	UFUNCTION(BlueprintCallable)
	AAmmo* GetAmmoHolderByIndex(int i);

	// Function to be called by the Level Handler that indicates round start
	UFUNCTION(BlueprintCallable)
	void StartingRoundByIndex(int RoundIndex);

	// Function to be called by the Level Handler that indicates round end
	UFUNCTION(BlueprintCallable)
	void EndingRound();

	// Getter function for IsRoundRunning
	bool GetIsRoundRunning();

	// Getter function for CurrentRound
	int GetCurrentRoundIndex();

	bool IsBlueAmmoEnabled();
	bool IsRedSpreadEnabled();
	bool IsBlueSpreadEnabled();

protected:
	virtual void BeginPlay() override;

private:
	// The name of the object fetched by the UObjectBaseUtility::GetName method
	const FString ObjectName;

	AAmmo *AmmoHolder[3];

	int MissingAmmoPair;

	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Bugs", meta = (AllowPrivateAccess = "true"))
	class UClass* AmmoUClass;

	// The paper flipbook component holding the sprites.
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
	class UPaperFlipbookComponent* PaperFlipbook;

	// The flipbook for the red ammo
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "AmmoTypes", meta = (AllowPrivateAccess = "true"))
	class UPaperFlipbook* RedAmmo;
	// The flipbook for the blue ammo
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "AmmoTypes", meta = (AllowPrivateAccess = "true"))
	class UPaperFlipbook* BlueAmmo;
	// The flipbook for the red spread ammo
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "AmmoTypes", meta = (AllowPrivateAccess = "true"))
	class UPaperFlipbook* RedSpread;
	// The flipbook for the blue spread ammo
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "AmmoTypes", meta = (AllowPrivateAccess = "true"))
	class UPaperFlipbook* BlueSpread;

	// Indicates if the round is online
	bool IsRoundRunning;

	// Number of the current round
	int CurrentRound;

	// Function that resets the Ammo Spawner for the next round
	void Reset();

	// Function that sets up the initial state of the round
	void SetupRound();

	//
	class ALevelHandler* LevelHandler;
};
