#include "UnixSocketClient.h"

UnixSocketClient::UnixSocketClient()
{

}

UnixSocketClient::~UnixSocketClient()
{

}

UnixSocketClient::Result UnixSocketClient::request(const Address& address, const std::string& message)
{
    UnixSocketClient::Result result;

    auto socket = std::make_unique<BerkeleySocket>(address.mHost, address.mPort);
    auto response = socket->send(message);

    if (socket->getState().mConnectStatus != Socket::State::ConnectStatus::FAILED)
    {
        result.mStatus = UnixSocketClient::Result::Status::OK;
        result.mBody = response;
    }
    else
    {
        result.mStatus = UnixSocketClient::Result::Status::FAILED;
        result.mErrorCode = socket->getState().mErrorCode;
        result.mErrorMessage = socket->getState().mErrorMessage;
    }
    return result;
}
