// SPDX-FileCopyrightText: 2015-2025 Alexey Rochev
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef TREMOTESF_SERVERSMODEL_H
#define TREMOTESF_SERVERSMODEL_H

#include <vector>
#include <QAbstractListModel>

#include "rpc/servers.h"

namespace tremotesf {
    class ServersModel final : public QAbstractListModel {
        Q_OBJECT

    public:
        explicit ServersModel(QObject* parent = nullptr);

        QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
        Qt::ItemFlags flags(const QModelIndex& index) const override;
        int rowCount(const QModelIndex& = {}) const override;
        bool setData(const QModelIndex& modelIndex, const QVariant& value, int role = Qt::EditRole) override;

        const std::vector<Server>& servers() const;
        const QString& currentServerName() const;

        bool hasServer(const QString& name) const;

        void setServer(
            const QString& oldName,
            const QString& name,
            ConnectionConfiguration connectionConfiguration,
            std::vector<MountedDirectory> mountedDirectories
        );
        void removeServerAtIndex(const QModelIndex& index);
        void removeServerAtRow(int row);

    private:
        int serverRow(const QString& name) const;

        std::vector<Server> mServers;
        QString mCurrentServer;
    };
}

#endif // TREMOTESF_SERVERSMODEL_H
