#ifndef DBCHANGEPROCESSOR_H
#define DBCHANGEPROCESSOR_H

#include <QObject>
#include <QTimer>
#include <QVector>
#include "core/eventbus.h"
#include "../core/events.h"

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

private slots:
    void handleMailItemAdded(const WinoMail::Events::MailItemAddedEvent& event);
    void handleMailItemRemoved(const WinoMail::Events::MailItemRemovedEvent& event);
    void handleMailItemUpdated(const WinoMail::Events::MailItemUpdatedEvent& event);
    void handleFolderAdded(const WinoMail::Events::FolderAddedEvent& event);
    void handleFolderRemoved(const WinoMail::Events::FolderRemovedEvent& event);
    void handleFolderUpdated(const WinoMail::Events::FolderUpdatedEvent& event);
    void handleAccountAdded(const WinoMail::Events::AccountAddedEvent& event);
    void handleAccountRemoved(const WinoMail::Events::AccountRemovedEvent& event);
    void handleAccountUpdated(const WinoMail::Events::AccountUpdatedEvent& event);
    void processBatch();

private:
    QTimer* m_batchTimer;
    QVector<WinoMail::Events::MailItemAddedEvent> m_mailItemAddedQueue;
    QVector<WinoMail::Events::MailItemRemovedEvent> m_mailItemRemovedQueue;
    QVector<WinoMail::Events::MailItemUpdatedEvent> m_mailItemUpdatedQueue;
    QVector<WinoMail::Events::FolderAddedEvent> m_folderAddedQueue;
    QVector<WinoMail::Events::FolderRemovedEvent> m_folderRemovedQueue;
    QVector<WinoMail::Events::FolderUpdatedEvent> m_folderUpdatedQueue;
    QVector<WinoMail::Events::AccountAddedEvent> m_accountAddedQueue;
    QVector<WinoMail::Events::AccountRemovedEvent> m_accountRemovedQueue;
    QVector<WinoMail::Events::AccountUpdatedEvent> m_accountUpdatedQueue;
};

#endif // DBCHANGEPROCESSOR_H