#include "request.h"

Request::Request(QObject *parent)
    : QObject(parent)
{
}

Request::Request(Method method, const QUrl &url, const QByteArray &body)
    : QObject(nullptr)
{
    setMethod(method);
    setUrl(url);
    setBody(body);
}

void Request::setMethod(Request::Method method)
{
    m_method = method;
}

Request::Method Request::method() const
{
    return m_method;
}

void Request::setUrl(const QUrl &url)
{
    m_url = url;
}

QUrl Request::url() const
{
    return m_url;
}

void Request::setHeader(const QString &key, const QString &value)
{
    m_headers.insert(key, value);
}

QMap<QString, QString> Request::headers() const
{
    return m_headers;
}

void Request::setBody(const QByteArray &body)
{
    m_body = body;
}

QByteArray Request::body() const
{
    return m_body;
}

void Request::setType(RequestType type)
{
    m_requestType = type;
}

RequestType Request::type() const
{
    return m_requestType;
}

void Request::setAccountId(const QString &accountId)
{
    m_accountId = accountId;
}

QString Request::accountId() const
{
    return m_accountId;
}

QNetworkRequest Request::toNetworkRequest() const
{
    QNetworkRequest netRequest(m_url);
    for (auto it = m_headers.constBegin(); it != m_headers.constEnd(); ++it) {
        netRequest.setRawHeader(it.key().toUtf8(), it.value().toUtf8());
    }
    return netRequest;
}
