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

#pragma once

#include "CoreMinimal.h"
#include "MainBountyClass.h"
#include "SideBountyClass.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "EndlessVendetta/InteractionInterface.h"
#include "EndlessVendetta/UserWidgets/PC_Display.h"
#include "GameFramework/Actor.h"
#include "BountyDirector.generated.h"

UCLASS()
class ENDLESSVENDETTA_API ABountyDirector : public AActor, public IInteractionInterface
{
	GENERATED_BODY()
	
	AEndlessVendettaCharacter* PlayerChar;

	// Scene Component Used to Attach Bounties to
	UArrowComponent* BountyAttachmentPoint;

	// Ordered Array of Main Bounties
	UPROPERTY(EditDefaultsOnly, Category = "Bounty Director")
	TArray<TSubclassOf<AMainBountyClass>> BountyClassArray;

	UPROPERTY(EditDefaultsOnly, Category = "Bounty Director")
	int FavourCost = 500;

	UPROPERTY(EditDefaultsOnly, Category = "Bounty Director")
	TSubclassOf<UPC_Display> PC_DisplayWidgetClass;
	
	UUserWidget* PC_DisplayWidget;

	UPC_Display* PC_Display;

	int CurrentBountyIndex = 0;

	UPROPERTY(VisibleAnywhere, Category = "Bounty")
	AMainBountyClass* ActiveBounty;

	UPROPERTY(VisibleAnywhere, Category = "Bounty")
	TArray<ASideBountyClass*> ActiveSideBounties;

	// Checks if completed the bounty, and moves onto the next if so
	void UpdateBountyProgression();

	void SpawnBountyAndItsSideBounties();
	
	// Collect reward for current Bounty and prepare for the next
	void FinishActiveBounty();

	// Opens up Bounty Director PC Interface
	void Interact() override;
	
	// Prompts player to interact
	void InteractPrompt() override;
protected:
	int Favours = 20;
	
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
		
	UFUNCTION()
	void DestroyActiveSideBounties();

	UFUNCTION()
	void DestroyBountyDirectorPCWidget();

	// Listens for when a side bounty is completed
	UFUNCTION()
	void EarnFavours(int FavoursEarned);
	
// -------- Buy Buttons --------
	UFUNCTION()
	void BuyCustomBountyAlteration_1();

	UFUNCTION()
	void BuyCustomBountyAlteration_2();

	UFUNCTION()
	void BuyCustomBountyAlteration_3();
	
	UFUNCTION()
	void BuyAmmoDrop();

	UFUNCTION()
	void BuyHealthDrop();

	UFUNCTION()
	void BuyEnemyRadio();

	UFUNCTION()
	void BuyFavours();

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// Sets default values for this actor's properties
	ABountyDirector();

	// ------ Getters ------
	FString GetBountyTitle()
	{
		return !IsValid(ActiveBounty) ? FString("") : ActiveBounty->GetBountyTitle();
	}

	UTexture2D* GetBountyIcon()
	{
		return !IsValid(ActiveBounty) ? nullptr : ActiveBounty->GetActiveWaypointIcon();
	}
	
	FString GetBountyDescription()
	{
		return !IsValid(ActiveBounty) ? FString("") : ActiveBounty->GetBountyDesc();
	}

	int GetBountyReward()
	{
		return !IsValid(ActiveBounty) ? 0 : ActiveBounty->GetBountyrewardMoney();
	}
	
};
