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

#pragma once

#include "CoreMinimal.h"
#include "WidgetControllerBase.h"
#include "Faye/Data/ShopListDataAsset.h"
#include "PhoneWidgetController.generated.h"

struct FTimeChangedPayload;
class UItem;
class ATimeOfDayActor;

UCLASS(BlueprintType)
class FAYE_API UItemSaleSlot: public UObject
{
	GENERATED_BODY()
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FItemSaleDataStruct ItemSaleRowData;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	bool bSold = false;
};

/**
 * 
 */
UCLASS()
class FAYE_API UPhoneWidgetController : public UWidgetControllerBase
{
	GENERATED_BODY()
public:
	virtual void InitializeController_Implementation() override;
	
	UFUNCTION(BlueprintCallable, Category = "Faye Widget Controller")
	TArray<UItemSaleSlot*> GetItemsForSale() const { return ItemsForSale; }
	
	UFUNCTION(BlueprintCallable, Category = "Faye Widget Controller")
	bool PurchaseSlot(int32 slotIndex);
	
protected:
	
	UFUNCTION()
	void OnTimeChanged(FTimeChangedPayload TimeChangedPayload);
	
	void GenerateShop();
	TArray<UItem*> GetBookDropsForSlot(const UItemSaleSlot* Slot) const;
	static EBookCategory GetWeightedCategory(const TMap<EBookCategory, int32>& Weights);
	
	UPROPERTY()
	ATimeOfDayActor* TimeOfDayActor = nullptr;
	int32 LastDayChecked = -1;

	UPROPERTY()
	UShopListDataAsset* ShopItemsData = nullptr;
	
	UPROPERTY()
	TArray<UItemSaleSlot*> ItemsForSale;
};
