#ifndef REQUESTPROCESSOR_H
#define REQUESTPROCESSOR_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include "request.h"

class RequestProcessor : public QObject
{
    Q_OBJECT
public:
    explicit RequestProcessor(QObject *parent = nullptr);
    ~RequestProcessor() override = default;

    void execute(Request *request);
    void cancelAll();

signals:
    void requestFinished(const QString &accountId, const QJsonDocument &response);
    void requestFailed(const QString &accountId, int httpCode, const QString &errorMessage);

private slots:
    void onReplyFinished(QNetworkReply *reply);

private:
    QNetworkAccessManager *m_networkManager;
    QMap<QNetworkReply*, Request*> m_pendingRequests;
};

#endif // REQUESTPROCESSOR_H
