#include "WinsockClient.h"

WinsockClient::WinsockClient()
    : mSocketInterface(std::make_unique<WinsockInterface>())
{
    mSocketInterface->initializeWinsock();
}

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

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

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