#include "NetworkManager.h"
#ifdef __linux__
#include "UnixSocketInterface.h"
#endif

#include <iostream>

NetworkManager::NetworkManager()
    : mActiveSockets(),
      mSocketInterface()
{

}

NetworkManager::~NetworkManager()
{

}

std::unique_ptr<NetworkManager> NetworkManager::Create()
{
    return std::make_unique<NetworkManager>();
}

void NetworkManager::Initialize()
{
#ifdef __linux__
    mSocketInterface = UnixSocketInterface::Create();
#endif
}

void NetworkManager::RunHttpServer()
{
	std::cout << "Running http server" << std::endl;
    if (!mSocketInterface)
    {
        Initialize();
    }

    auto socket = Socket::Create();
    mSocketInterface->InitializeSocket(socket);
    mSocketInterface->Listen(socket);
    mSocketInterface->Run(socket);
}

void NetworkManager::RunHttpClient()
{
	std::cout << "Running http client" << std::endl;
    if (!mSocketInterface)
    {
        Initialize();
    }

    auto socket = Socket::Create();
    mSocketInterface->InitializeSocket(socket, "127.0.0.1");
    mSocketInterface->Write(socket, "Hello Friend");
}

void NetworkManager::ShutDown()
{

}
