#ifndef DESKTOPDATAHANDLER_H
#define DESKTOPDATAHANDLER_H

#include <QObject>
#include "modelmanager.h"
#include "tabletdesktopbackend.h"
#include "types.h"

class DesktopDataHandler : public QObject
{
    Q_OBJECT
public:
    explicit DesktopDataHandler(QObject *parent = nullptr);
    ~DesktopDataHandler();

    QString categoryName(int category) const;
    QList<quint32> apps() const;
    QMap<quint32, UKUI::BaseItem *> items() const;
    QMap<UKUI::Categories, QString> categories() const;
    QMap<UKUI::Categories, QList<quint32>> categoriesItems() const;

public Q_SLOTS:
    void init();
    void setGroupName(const QString &name,int groupId);
    void updateGroup(const QList<QList<quint32> > &ids, int groupId);
    void createGroup(quint32 groupId, const QList<quint32> &itemIdList, const QString &groupName);
    void removeGroup(quint32 groupId);

private Q_SLOTS:
    void updateDekstopData();
    void addItem(quint32 itemId, int page);
    void removeItem(quint32 itemId, int page);
    void iconThemeChanged();
    void changeTaskBarApp(appChangeInfo appChangeData);

Q_SIGNALS:
    void finished();
    void desktopData(const QMap<quint32, QList<quint32>> &pageData,
                     const QMap<quint32, QList<QList<quint32>>> &setData,
                     const QMap<quint32, UKUI::BaseItem *> &itemData);
    void categoriesData(QMap<UKUI::Categories, QList<quint32>> categoriesItems);
    void itemAdded(int itemId, QList<int> categories);
    void appUninstalledFromGroup(int itemId, int group);
    void appUninstalled(int itemId);
    ///
    /// \brief appInstalled 有新的应用安装完成之后发出该信号
    /// \param itemId 新应用的id
    /// \param indexOfAllCategory 新应用在‘全部’分类中的索引
    /// \param indexOfCategory 新应用在本身所在分类中的索引
    /// \param page 如果是非大屏项目的话，该参数不能为-1
    /// \param newCategory 是否是新的分类
    /// \param category 新分类
    ///
    void appInstalled(int itemId,
                      int indexOfAllCategory,
                      int indexOfCategory,
                      int page = -1,
                      bool newCategory = false,
                      int category = CategoryItem::All);
    void iconChanged();
    void pageRemoved(int page, int groupId);
    void taskbarDataChange(appChangeInfo appChangeData);
    void uninsatllApp(const QString &desktopFile);

private:
    int groupIdOfItem(int itemId);

private:
    UKUI::TabletDesktopBackend *m_dataBackend;
    QMap<quint32, QList<quint32>> m_pageData;
    QMap<quint32, QList<QList<quint32>>> m_setData;
    QMap<quint32, UKUI::BaseItem *> m_itemsData;
    QMap<UKUI::Categories, QString> m_categories;
    QMap<UKUI::Categories, QList<quint32>> m_categoriesItems;
    QList<quint32> m_apps;
};

#endif // DESKTOPDATAHANDLER_H
