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

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "EpicEnumsAndStructs.h"
#include "AC_PlayerInventory.generated.h"

//Forward Declarations




UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class EPIC_INVENTORY_API UAC_PlayerInventory : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UAC_PlayerInventory();

	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration")
	bool bUseRequiredLevel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration")
	bool bStackSameItemsInInventoryUI;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration")
	bool bUseInventoryCap;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration", meta = (EditCondition = "bUseInventoryCap", EditConditionHides, Tooltip = "Select the type of inventory cap. WEIGHT uses item weight, TOTAL uses total number of items, TOTAL PER CATEGORY uses a cap per category of inventory item"))
	EInventoryCapType InventoryCapType;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration", meta = (EditCondition = "InventoryCapType == EInventoryCapType::TotalItems && bUseInventoryCap", EditConditionHides))
	int32 InventoryMaxCapacity = 100;

	UPROPERTY(BlueprintReadWrite)
	int32 InventoryCurrentCapacity = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration", meta = (EditCondition = "InventoryCapType == EInventoryCapType::TotalItemsPerCategory && bUseInventoryCap", EditConditionHides))
	TMap<EItemType, int32> InventoryCapacityPerCategory;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Starting Items")
	TArray<FStartingItems> StartingItems;

	// Initialize the inventory component with default inventory, if any.
	UFUNCTION(BlueprintCallable)
	void InitializePlayerInventory();

	UFUNCTION(BlueprintCallable)
	TArray<FBaseItemInfo> GetPlayerInventory();

	UFUNCTION(BlueprintCallable)
	void RequestAddItem(FBaseItemInfo InItemInfo, int32 InItemQuantity, AActor* ActorToDelete);

	UFUNCTION(BlueprintCallable)
	TArray<FBaseItemInfo> GetAllInventoryItemsInCategory(EItemType InItemType);

	UFUNCTION(BlueprintCallable)
	EInventoryCapType GetInventoryCapType();

	UFUNCTION(BlueprintCallable)
	int32 CountNumberOfSameItemsInInventory(const FBaseItemInfo& ItemToCheck);

	UFUNCTION(BlueprintCallable)
	void RequestDropItem(const FBaseItemInfo& ItemToDrop, const int32& ItemCount);



protected:
	// Called when the game starts
	virtual void BeginPlay() override;

private:

	//Master player inventory variable
	
	TArray<FBaseItemInfo> PlayerInventory;
		
};


