#ifndef INTERACTIVEDATA_H
#define INTERACTIVEDATA_H
#include <QMap>
#include <QList>
#include <QVector>
#include <QString>

#include <QReadWriteLock>
#include <QReadLocker>
#include <QWriteLocker>
#include <QtQml>

#define MATERIALS_TYPE_ALL "0"

class InteractiveData : public QObject
{
    Q_OBJECT
    QML_SINGLETON
    QML_NAMED_ELEMENT(InteractiveData)

    Q_PROPERTY(QSet<QString> roles READ roles WRITE setRoles NOTIFY rolesChanged)
    Q_PROPERTY(QSet<QString> permissions READ permissions WRITE setPermissions NOTIFY permissionsChanged)
signals:
    void rolesChanged();
    void permissionsChanged();
    /** API 请求超时(408)时发出，QML 可统一显示超时弹窗 */
    void requestTimedOut();

public:
    static InteractiveData* pInstance;
    static InteractiveData* instance();
    static InteractiveData* create(QQmlEngine*, QJSEngine*);

    Q_INVOKABLE bool isHavePower(const QString &operation);
    /** 清空 m_token（系统启动、登录失败、退出登录时调用），同时清空 InteractiveHttp::strToken 与 HttpClient::sToken */
    Q_INVOKABLE void clearToken();
    /** C++ 侧检测到 API 408 时调用，发出 requestTimedOut 供 QML 显示超时弹窗 */
    void notifyRequestTimedOut();

    QSet<QString> roles();
    void setRoles(const QSet<QString> &roles);
    QSet<QString> permissions();
    void setPermissions(const QSet<QString> &permissions);

    void cleanJobTicketsModel();

    ~InteractiveData();
private:
    explicit InteractiveData();
public:
    QString m_userName;                     // 用户名
    QSet<QString> m_roles;                  // 用户角色
    QSet<QString> m_permissions;            // 用户许可

    QString m_token;
};

inline InteractiveData* GetInteractiveData()
{
    return InteractiveData::instance();
}
#endif // INTERACTIVEDATA_H
