/**
 * SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org>
 *
 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
 */

#pragma once

#include <QAbstractListModel>
#include <QHash>
#include <QQmlEngine>
#include <QSqlTableModel>
#include <QUrl>

#include "feed.h"

#include <memory>

class FeedsModel : public QAbstractListModel
{
    Q_OBJECT
    QML_ELEMENT

public:
    explicit FeedsModel(QObject *parent = nullptr);
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;
    int rowCount(const QModelIndex &parent) const override;
    Q_INVOKABLE void removeFeed(const QString &url);
    Q_INVOKABLE void refreshAll();

private:
    void loadFeed(int index) const;

    mutable std::vector<std::unique_ptr<Feed>> m_feeds;
};
