// Copyright CodeSpartan, 2022. All rights reserved.

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MmoUtilities.generated.h"

UENUM(BlueprintType)
enum class LogVerbosity : uint8
{
	Verbosity_DoNotDisplay	UMETA(DisplayName = "DoNotDisplay"),
	Verbosity_SuperVerbose	UMETA(DisplayName = "SuperVerbose"),
	Verbosity_Normal		UMETA(DisplayName = "Normal"),
};
/**
 * 
 */
UCLASS(BlueprintType)
class MMOKITCODE_API UMmoUtilities : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:

	UFUNCTION(BlueprintCallable, Category = "MMO Utility", meta = (WorldContext = "WorldContextObject"))
	static bool InPieWorld(UObject* WorldContextObject);

	UFUNCTION(BlueprintCallable, Category = "MMO Utility", meta = (WorldContext = "WorldContextObject"))
	static int32 GetPieWindowId(UObject* WorldContextObject);

	UFUNCTION(BlueprintCallable, Category = "MMO Utility", meta = (WorldContext = "WorldContextObject"))
	static int32 GetServerPort(UObject* WorldContextObject);

	UFUNCTION(BlueprintCallable, Category = "MMO Utility")
	static bool CheckCommandLineParam(FString Param);

	UFUNCTION(BlueprintCallable, Category = "MMO Utility")
	static bool GetCommandLineValue(FString Param, FString& Value);

	UFUNCTION(BlueprintCallable, BlueprintPure, Category = "MMO Utility")
	static FString GetSteamSessionTicket();

	UFUNCTION(BlueprintCallable, BlueprintPure, Category = "MMO Utility")
	static FString GetSteamUserId();

	UFUNCTION(BlueprintCallable, BlueprintPure, Category = "MMO Utility")
	static bool IsWithSteam();

	UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, Keywords = "log print", AdvancedDisplay = "3", DevelopmentOnly), Category = "MMO|Utilities")
	static void LogString(const UObject* WorldContextObject, const FString& InString = FString(TEXT("Hello")), const LogVerbosity Verbosity = LogVerbosity::Verbosity_SuperVerbose, bool bPrintToScreen = true, bool bPrintToLog = true, FLinearColor TextColor = FLinearColor(0.0, 0.66, 1.0), float Duration = 2.f, const FName Key = NAME_None);

	/* Convert an Object into an array of bytes. Only properties marked as SaveGame will be captured by this method. */
	UFUNCTION(BlueprintCallable, Category = "MMO Utility")
	static TArray<uint8> SerializeObject(UObject* Obj);

	/* Populate an Object with property values taken from an array of bytes. The Object must be spawned beforehand. */
	UFUNCTION(BlueprintCallable, Category = "MMO Utility")
	static void DeserializeObject(UObject* Obj, const TArray<uint8> Bytes);

	UFUNCTION(BlueprintCallable, BlueprintPure, Category = "MMO Utility")
	static FName GetAssetName(const FTopLevelAssetPath& TopLevelAssetPath);

	UFUNCTION(BlueprintCallable, CustomThunk, Category = "Json", meta = (CustomStructureParam = "Value"))
	static UPARAM(DisplayName = "Success") bool ConvertJsonStringToStruct(const FString& JsonString, int32& Value);
	DECLARE_FUNCTION(execConvertJsonStringToStruct);

	UFUNCTION(BlueprintCallable, CustomThunk, Category = "Json", meta = (CustomStructureParam = "Struct"))
	static UPARAM(DisplayName = "Success") bool LoadJsonFromStruct(const int32& Struct, FJsonObjectWrapper& JsonObject);
	DECLARE_FUNCTION(execLoadJsonFromStruct);
};
