#ifndef LAUNCHERITEM_H
#define LAUNCHERITEM_H

#include <QObject>
#include <QAbstractListModel>
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
#include <QtQml/qqml.h>
#endif

struct LauncherItemPrivate;
class LauncherItem : public QObject
{
    Q_OBJECT
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
    QML_ELEMENT
#endif
    Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
    Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged)
    Q_PROPERTY(int type READ type WRITE setType NOTIFY typeChanged)
    Q_PROPERTY(int pageIndex READ pageIndex WRITE setPageIndex NOTIFY pageIndexChanged)
    Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
    Q_PROPERTY(QString desktopFile READ desktopFile WRITE setDesktopFile NOTIFY desktopFileChanged)
    Q_PROPERTY(QList<int> categories READ categories WRITE setCategories NOTIFY categoriesChanged)
    Q_PROPERTY(int location READ location WRITE setLocation NOTIFY locationChanged)
    Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan NOTIFY rowSpanChanged)
    Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan NOTIFY columnSpanChanged)
    Q_PROPERTY(int state READ state WRITE setState NOTIFY stateChanged)
    Q_PROPERTY(bool editable READ editable WRITE setEditable NOTIFY editableChanged)
    Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged)
    Q_PROPERTY(bool appOpen READ appOpen WRITE setAppOpen NOTIFY appOpenChanged)
    Q_PROPERTY(int windowId READ windowId WRITE setWindowId NOTIFY windowIdChanged)
    Q_PROPERTY(bool nameVisible READ nameVisible WRITE setNameVisible NOTIFY nameVisibleChanged)
    Q_PROPERTY(QAbstractListModel * model READ model WRITE setModel NOTIFY modelChanged)
    Q_PROPERTY(QString qmlFile READ qmlFile WRITE setQmlFile NOTIFY qmlFileChanged)
    Q_PROPERTY(bool uninstallable READ uninstallable WRITE setUninstallable NOTIFY uninsatllableChanged)

public:
    enum ItemType {
        AppIcon = 1,
        Group = 2,
        Container = 4,
        Widget = 8,
        Placeholder = 16,
        AddIcon = 32,
        WindowIcon = 64,
        AllType = 128,
    };
    enum ItemState {
        Normal = 1,
        Editable = 2,
        Selectable = 4,
        Under = 8, // 在拖动的图标的下方
        Popup = 16, // 弹出分组显示
        Dragging = 32
    };
    Q_ENUM(ItemType)
    Q_ENUM(ItemState)

    explicit LauncherItem(QObject *parent = nullptr);
    LauncherItem(const LauncherItem &other);
    ~LauncherItem();
    LauncherItem &operator= (const LauncherItem &other);

    QString name() const;
    void setName(const QString &name);

    int id() const;
    void setId(const int &id);

    int type() const;
    void setType(const int &type);

    int pageIndex() const;
    void setPageIndex(const int &pageIndex);

    QString icon() const;
    void setIcon(const QString &icon);

    QString desktopFile() const;
    void setDesktopFile(const QString &desktopFile);

    QList<int> categories() const;
    void setCategories(const QList<int> &categories);

    int location() const;
    void setLocation(const int &location);

    int rowSpan() const;
    void setRowSpan(const int &rowSpan);

    int columnSpan() const;
    void setColumnSpan(const int &columnSpan);

    int state() const;
    void setState(const int &state);

    bool editable() const;
    void setEditable(const bool &editable);

    bool selected() const;
    void setSelected(bool selected);

    bool appOpen() const;
    void setAppOpen(const bool &appOpen);

    int windowId() const;
    void setWindowId(const int &windowId);

    bool nameVisible() const;
    void setNameVisible(const bool &nameVisible);

    QAbstractListModel *model() const;
    void setModel(QAbstractListModel *model);

    QString qmlFile() const;
    void setQmlFile(const QString &qmlFile);

    bool uninstallable() const;
    void setUninstallable(const bool &uninstallable);

Q_SIGNALS:
    void nameChanged();
    void idChanged();
    void typeChanged();
    void indexChanged();
    void pageIndexChanged();
    void iconChanged();
    void desktopFileChanged();
    void categoriesChanged();
    void locationChanged();
    void rowSpanChanged();
    void columnSpanChanged();
    void stateChanged();
    void editableChanged();
    void selectedChanged();
    void appOpenChanged();
    void windowIdChanged();
    void nameVisibleChanged();
    void modelChanged();
    void qmlFileChanged();
    void uninsatllableChanged();

private:
    LauncherItemPrivate *p;
};

#endif // LAUNCHERITEM_H
