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

#pragma once

#include "CoreMinimal.h"
#include "CheckpointClass.h"
#include "GameFramework/Actor.h"
#include "BountyClass.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FCompletedFirstCheckpoint);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FCompletedACheckpoint);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCheckpointActivated, const FString&, CheckpointTip);

UCLASS()
class ENDLESSVENDETTA_API ABountyClass : public AActor
{
	GENERATED_BODY()

// ------------------- ATTRIBUTES ------------------------------

	// Array of Checkpoint Classes to Spawn for this Bounty
	UPROPERTY(EditDefaultsOnly, Category = "Bounty")
	TArray<TSubclassOf<ACheckpointClass>> CheckpointsToSpawn;

protected:
	// Array of References to the Spawned in Checkpoints for this Bounty
	TArray<ACheckpointClass*> BountyCheckpoints;

	// Money Rewarded to Player for Completing this Bounty
	UPROPERTY(EditDefaultsOnly, Category = "Bounty")
	int RewardMoney = 0;

public:
	FCompletedACheckpoint CompletedACheckpoint;

	FCheckpointActivated CheckpointActivated;

	// Gets the Reward Money for Completing this Bounty, used by Players Character
	int GetRewardMoney()
	{
		return RewardMoney;
	}
	

// ------------------- METHODS ---------------------------------
private:
	
	
protected:
	// Called when a checkpoint is completed, handles moving onto next checkpoint and discarding the old one
	UFUNCTION()
	virtual void IncrementBountyCheckpoint();

public:
	// Sets default values for this actor's properties
	ABountyClass();
	
	// Spawns and stores this Bounties Checkpoints in order
	virtual void SpawnCheckpoints();

	// Activate the First Checkpoint in Bounty Checkpoints and Listen for its Completion
	virtual void ActivateFirstCheckpoint();

	// De-Activate the First Checkpoint in Bounty Checkpoints
	virtual void DeActivateFirstCheckpoint();



	
	
// ------------------- LEGACY CODE TO BE REWORKED ---------------------------------
	
	
	bool BountyStarted = false;

protected:
	// ------- Properties Set in Editor --------------
	
          
	

	UPROPERTY(EditDefaultsOnly, Category = "Bounty")
	FString BountyTitle;

	UPROPERTY(EditDefaultsOnly, Category = "Bounty")
	FString BountyDesc;
	// -----------------------------------------------
	
public:
	// Broadcast when first checkpoint from this bounty is completed
	FCompletedFirstCheckpoint CompletedFirstCheckpoint;

	
	
	// ------ Getters for Bounty and Checkpoint Properties ------
	bool IsCompleted()
	{
		return false;
	}
	
	FString GetBountyTitle()
	{
		return BountyTitle;
	}

	FString GetBountyDesc()
	{
		return BountyDesc;
	}

	int GetBountyrewardMoney()
	{
		return RewardMoney;
	}

	FVector GetCheckpointLocation()
	{
		if (BountyCheckpoints.IsEmpty() || BountyCheckpoints[0] == nullptr)
		{
			return FVector(0, 0, 0);
		}

		return BountyCheckpoints[0]->GetCheckpointSpawnTransform().GetLocation();
	}

	FVector GetActiveWaypointLocation()
	{
		if (BountyCheckpoints.IsEmpty() || BountyCheckpoints[0] == nullptr)
		{
			return FVector(0, 0, 0);
		}

		return BountyCheckpoints[0]->GetWaypointLoc();
	}

	UTexture2D* GetActiveWaypointIcon()
	{
		if (BountyCheckpoints.IsEmpty() || BountyCheckpoints[0] == nullptr)
		{
			return nullptr;
		}

		return BountyCheckpoints[0]->GetWaypointIcon();
	}
	
	// ----------------------------------------------------------
	

	// Collect Money in C++, any other special reward will be implemented in BP if neccessary
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
	void CollectRewards();
};
