// 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;
};

USTRUCT(BlueprintType)
struct FAgrarianSavedContainer
{
	GENERATED_BODY()

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

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

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

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

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

USTRUCT(BlueprintType)
struct FAgrarianSavedTileRegistryState
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FName ActiveTileId = TEXT("gz_us_ca_pacifica_utm10n_e544_n4160");

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FString RegistryPath = TEXT("Data/Tiles/ground_zero_tiles.json");

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	int32 RegistrySchemaVersion = 1;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	int32 GenerationVersion = 1;

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

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;

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

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Save")
	FAgrarianSavedTileRegistryState TileRegistry;
};
