// Copyright Pacificao. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/SaveGame.h"
#include "AgrarianTypes.h"
#include "AgrarianSaveGame.generated.h"

USTRUCT(BlueprintType)
struct FAgrarianSavedPlayerIdentity
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FString StablePlayerId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FString PlayerName;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FString NetworkId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	bool bUsedNetworkId = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FString LastKnownPawnName;
};

USTRUCT(BlueprintType)
struct FAgrarianSavedPlayer
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FString PlayerId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FAgrarianSavedPlayerIdentity Identity;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FTransform Transform;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FAgrarianSurvivalSnapshot Survival;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FAgrarianCareHistorySnapshot CareHistory;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	TArray<FAgrarianItemStack> Inventory;
};

USTRUCT(BlueprintType)
struct FAgrarianSavedWorldActor
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FName ActorTypeId = NAME_None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FTransform Transform;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	TMap<FName, FString> StringState;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	TMap<FName, float> NumberState;
};

USTRUCT(BlueprintType)
struct FAgrarianSavedResourceNode
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FName ResourceNodeId = NAME_None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	int32 RemainingHarvests = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	bool bRespawnsForMvp = false;
};

UCLASS()
class UAgrarianSaveGame : public USaveGame
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	int32 SaveVersion = 1;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	float WorldHours = 8.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	EAgrarianWeatherType Weather = EAgrarianWeatherType::Clear;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FAgrarianMappedWeatherInputs WeatherInputs;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FAgrarianWeatherDebugSnapshot WeatherDebug;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	TArray<FAgrarianSavedPlayer> Players;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	TArray<FAgrarianSavedWorldActor> WorldActors;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	TArray<FAgrarianSavedResourceNode> ResourceNodes;
};
