#pragma once

#include "Dom/JsonValue.h"
#include "Dom/JsonObject.h"
#include "UObject/Object.h"
#include "EmoShapeSubSystem/EmoShapeIOLib/Public/sio_client.h"
#include "ESMessageConvert.generated.h"

DECLARE_LOG_CATEGORY_EXTERN(SocketIO, Log, All);

USTRUCT(BlueprintType)
struct EMOSHAPESUBSYSTEM_API FEmoShapeConnectParams
{
	GENERATED_USTRUCT_BODY();

	/** Default connection address string in form e.g. http://localhost:80. */
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SocketIOConnectionParams)
	FString AddressAndPort;

	/** A map of query parameters to be added to connection url*/
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SocketIOConnectionParams)
	TMap<FString, FString> Query;

	/** A map of headers to be added to connection url*/
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SocketIOConnectionParams)
	TMap<FString, FString> Headers;

	/** Optional path part of URL string. Default is 'socket.io'*/
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SocketIOConnectionParams)
	FString Path;

	FEmoShapeConnectParams()
	{
		AddressAndPort = TEXT("http://localhost:3000");
		Path = TEXT("socket.io");
	}
};

UCLASS()
class EMOSHAPESUBSYSTEM_API UESMessageConvert : public UObject
{
	GENERATED_BODY()
public:

	//To from:

	//emoshapeio::message <-> FJsonValue
	static TSharedPtr<FJsonValue> ToJsonValue(const emoshapeio::message::ptr& Message);
	static emoshapeio::message::ptr ToSIOMessage(const TSharedPtr<FJsonValue>& JsonValue);

	//std::string <-> FString
	static std::string StdString(FString UEString);
	static FString FStringFromStd(std::string StdString);

	static std::map<std::string, std::string> JsonObjectToStdStringMap(TSharedPtr<FJsonObject> InObject);
	static TMap<FString, FString> JsonObjectToFStringMap(TSharedPtr<FJsonObject> InObject);
	static std::map<std::string, std::string> FStringMapToStdStringMap(const TMap<FString, FString>& InMap);
};
