#ifndef LOGICBURNDATA_H
#define LOGICBURNDATA_H

#include <QAbstractItemModel>
#include <QIcon>

class LogicBurnData : public QAbstractItemModel
{
    Q_OBJECT

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

    // Header:
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;

    // Basic functionality:
    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;

    // Editable:
    bool setData(const QModelIndex &index, const QVariant &value,
                 int role = Qt::EditRole) override;

    Qt::ItemFlags flags(const QModelIndex& index) const override;
    Qt::DropActions supportedDropActions() const override;

    QStringList mimeTypes() const;
    QMimeData *mimeData(const QModelIndexList &indexes) const;
    bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
public:
    bool isUp(QModelIndex);
    bool isFolder(QModelIndex);
    bool checkAdd(QModelIndex);
    bool checkAdd(QModelIndexList);
    bool checkDel(QModelIndexList);
    bool checkCls(QModelIndex);
    bool checkTip(QModelIndex);
    bool checkOpen(QModelIndexList);
    bool checkOpenLocal(QModelIndexList);
    bool checkProperties(QModelIndexList);
    bool checkSelectModelItem(QModelIndexList);
    bool checkSize();
    QString stringSize(unsigned long);
    int index() const { return m_iIndex; }
    unsigned int level(QModelIndex idx = QModelIndex());
    int filter(QModelIndex idx = QModelIndex());
    int doFilterHidden(QModelIndex idx = QModelIndex());
    int doRecoveryHidden(QList<void *>, QModelIndex);
    int doFilterBroken(QModelIndex idx = QModelIndex());
    int doRecoveryBroken(QList<void *>, QModelIndex);
    int doFilterRepleace(QModelIndex idx = QModelIndex());
    int doRecoveryRepleace(QList<void *>);
public slots:
    void changeIndex(int);
    int addDatasToIndex(QStringList, QModelIndex);
    int deleteDatasFromIndex(QModelIndexList, QModelIndex);
    int clearDatasUnderIndex(QModelIndex);
    int clearDatasUnderIndexd(QModelIndex);
    bool duplicatedName(QString, QModelIndex);
    void addEmptyFolder(QString, QModelIndex);
    void deleteRoot(int);
    void recovery(QList<void *> hiddens, QList<void *> brokens, QList<void *> replaces);
private slots:
    void slotsSetting();
    void slotsCreateISO(void *);
    void slotsCreateISO();
    void slotsBurnData();
    void slotsBurnUDFData();
    void slotsEmptyMedium(void *);
    void slotsUpdateCDROM();
    void slotsDoFilterHidden(void *);
    void slotsDoFilterBroken(void *);
    void slotsDoRepleace(void *);
    void slotsUpdateSize(unsigned long);
private:
    int addDiskData(QStringList, void *);
    int needAdd(QStringList);
    int needAdd(QString);
    int addDirectoy(QString, void *, bool disk = false);
    int addFile(QString, void *, bool disk = false);
   // bool isAbleBurnData(); // 通过判断新加入文件的容量与光盘剩余容量大小，决定是否可以刻录
private:
    int           m_iIndex;
    bool          m_bCancel;
    bool          m_bAppRunning;
    QStringList   m_oHHeaders;
    QStringList   m_oVHeaders;
    QList<void *> m_oRoots;
    QList<void *> m_oBurners;
signals:
    // log
    void info(QString); void warn(QString);
    void error(QString); void debug(QString);

    void setting(void *);
    void rootIndex(QModelIndex);
    void size(unsigned long);
    // progress
    void title(QString);
    void setRange(int, int);
    void setValue(int, QIcon icon = QIcon(), QString str = QString());
    void addValue(int, QIcon icon = QIcon(), QString str = QString());
    // check
    void tip(bool); void add(bool); void del(bool); void cls(bool); void folder(bool);
    // update combobox
    void updateDisk(int, void *);
    // filter
    void newFilterNode(QIcon, QString);
    void doHidden(int, void *);
    void doBroken(int, void *);
    void doRepleace(int, void *);
};

#endif // LOGICBURNDATA_H
