// © 2025 Naked People Team. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/SaveGame.h"
#include "NakedDesire/Global/Constants.h"
#include "ItemSaveRecord.h"
#include "NakedDesire/Commissions/CommissionTypes.h"
#include "GlobalSaveGameData.generated.h"

class UItemInstance;

UCLASS()
class NAKEDDESIRE_API UGlobalSaveGameData : public USaveGame
{
	GENERATED_BODY()

public:
	static UGlobalSaveGameData* CreateNewSaveGame();
	static UGlobalSaveGameData* LoadGame(const FString& SlotName = DefaultSaveSlotName);
	static bool SaveGame(UGlobalSaveGameData* SaveGameData, const FString& SlotName = DefaultSaveSlotName);

	UPROPERTY(SaveGame)
	bool HaveSeenTutorial = false;

	UPROPERTY(SaveGame)
	float Money = 0;
	
	FItemSaveRecord AddWardrobeItem(const UItemInstance* ItemInstance);
	bool UpdateWardrobeItem(UItemInstance* ItemInstance);
	bool RemoveWardrobeItem(UItemInstance* ItemInstance);
	TArray<FItemSaveRecord> GetWardrobeItems() const { return WardrobeItems; }

	FItemSaveRecord AddEquippedItem(const UItemInstance* ItemInstance);
	void AddEquippedItem(const FItemSaveRecord& ItemRecord);
	bool UpdateEquippedItem(UItemInstance* ItemInstance);
	bool RemoveEquippedItem(UItemInstance* ItemInstance);
	TArray<FItemSaveRecord> GetEquippedItems() const { return EquippedItems; }

	FItemSaveRecord AddWorldItem(const UItemInstance* ItemInstance, FTransform Transform);
	bool UpdateWorldItem(UItemInstance* ItemInstance, FTransform Transform);
	bool RemoveWorldItem(UItemInstance* ItemInstance);
	TArray<FItemSaveRecord> GetWorldItems() const { return WorldItems; }

	// Commission board state (§13). State-level only; see FCommissionSaveRecord.
	TArray<FCommissionSaveRecord> GetCommissionRecords() const { return Commissions; }
	void SetCommissionRecords(const TArray<FCommissionSaveRecord>& InRecords) { Commissions = InRecords; }

	UPROPERTY(SaveGame)
	int32 DaysPassed = 0;

	// Time of day in minutes since 00:00, range [0, 1440). Owned by UTimeOfDaySubsystem.
	UPROPERTY(SaveGame)
	float MinuteOfDay = DAY_START_HOUR * MINUTES_PER_HOUR; // start the campaign at 08:00

	// Endless mode disables the weekly rent charge / eviction (§3.3).
	UPROPERTY(SaveGame)
	bool bEndlessMode = false;

	// Day index of the most recent successful rent payment (book-keeping / bank UI).
	UPROPERTY(SaveGame)
	int32 LastRentChargeDay = 0;

private:
	UPROPERTY(SaveGame)
	TArray<FItemSaveRecord> WardrobeItems;

	UPROPERTY(SaveGame)
	TArray<FItemSaveRecord> EquippedItems;

	UPROPERTY(SaveGame)
	TArray<FItemSaveRecord> WorldItems;

	UPROPERTY(SaveGame)
	TArray<FCommissionSaveRecord> Commissions;
};