#include "folderservice.h"
#include "core/synchronizerprovider.h"
#include <QDebug>

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

QVector<Folder> FolderService::getFoldersForAccount(const QString &accountId)
{
    return FolderDao::findByAccountId(accountId.toInt());
}

void FolderService::refreshFolders(const QString &accountId)
{
    Synchronizer *sync = SynchronizerProvider::instance().getSynchronizer(accountId);
    if (sync) {
        QVector<Folder> folders = sync->getFolders();
        for (const auto &f : folders) {
            FolderDao::insert(f);
        }
    }
    emit foldersChanged(accountId);
}

Folder FolderService::getFolderById(const QString &folderId)
{
    std::optional<Folder> f = FolderDao::findById(folderId.toInt());
    return f.value_or(Folder());
}

#include "folderservice.moc"