#pragma once

#include <QAbstractItemModel>
#include "qsacnuniverse.h"
#include "multiverseitem.h"

class QSacnNode; // forward declare node class

/**
 * @brief The MultiverseModel class
 */
class MultiverseModel
    : public QAbstractItemModel
{
  Q_OBJECT

public:
  /// @brief The Catagory enum
  enum Catagory {
    Discovery,
    Receiver,
    Source
  };
  Q_ENUM(Catagory)

  /// @brief The Column enum
  enum Column {
    Universe,
    Priority,
    Channels,
    Description
  };
  Q_ENUM(Column)

  explicit MultiverseModel(QObject *parent = nullptr,
                           QSacnNode *node = nullptr);
  virtual ~MultiverseModel();

  // Model overrides:
  QVariant headerData(int section, Qt::Orientation orientation,
                      int role = Qt::DisplayRole) const override;
  QModelIndex index(int row, int column,
                    const QModelIndex &parent = QModelIndex()) const override;
  QModelIndex parent(const QModelIndex &index) const override;
  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
  QVariant data(const QModelIndex &index,
                int role = Qt::DisplayRole) const override;
  Qt::ItemFlags flags(const QModelIndex &index) const override;

  // non-standard model operations
  MultiverseItem * root();
  void insert(const QModelIndex &parent,
              QSacnUniverse *universe = nullptr,
              discoveredUniverse *discovery = nullptr);
  void remove(const QModelIndex &parent,
              const QVariant &data);

  QMap<MultiverseModel::Catagory, QModelIndex> categoryIndexes;

public slots:
  void doDiscovery();
  void doSubscription(QSacnUniverse*);
  void doUnsubscribe(QSacnUniverse*);
  void doCreation(QSacnUniverse*);
  void doTerminate(QSacnUniverse*);

private:
  MultiverseItem * getItem(const QModelIndex &index) const;

  QSacnNode * node_;
  MultiverseItem  * rootItem_;
};



