#ifndef USERINFOMODEL_H
#define USERINFOMODEL_H
#include <QAbstractListModel>
#include <QtQml/qqml.h>

class UserInfoModel: public QObject
{
    Q_OBJECT
    QML_SINGLETON
    QML_NAMED_ELEMENT(UserInfoModel);

    Q_PROPERTY(int id READ id WRITE setId);
    Q_PROPERTY(QString username READ username WRITE setUsername NOTIFY signalUsernameChanged);
    Q_PROPERTY(QString nickname READ nickname WRITE setNickname NOTIFY signalNicknameChanged);
    Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY signalEmailChanged);
    Q_PROPERTY(QString mobile READ mobile WRITE setMobile NOTIFY signalMobileChanged);
    Q_PROPERTY(int sex READ sex WRITE setSex NOTIFY signalSexChanged);
    Q_PROPERTY(QString avatar READ avatar WRITE setAvatar NOTIFY signalAvatarChanged);
    Q_PROPERTY(QString loginIp READ loginIp WRITE setLoginIp);
    Q_PROPERTY(QString loginDate READ loginDate WRITE setLoginDate);
    Q_PROPERTY(QString createTime READ createTime WRITE setCreateTime);

    Q_PROPERTY(QString roles READ roles WRITE setRoles);
    Q_PROPERTY(QString dept READ dept WRITE setDept);
    Q_PROPERTY(QString posts READ posts WRITE setPosts);
private:
    explicit UserInfoModel(QObject *parent=nullptr);
    explicit UserInfoModel() = default;
    ~UserInfoModel();
public:
    static UserInfoModel* pInstance;
    static UserInfoModel* instance();
    static UserInfoModel* create(QQmlEngine*, QJSEngine*);

    int id() {
        return m_id;
    }
    void setId(int id) {
        m_id = id;
    }

    QString username() {
        return m_username;
    }
    void setUsername(const QString& username) {
        m_username = username;
    }

    QString nickname() {
        return m_nickname;
    }
    void setNickname(const QString& nickname) {
        m_nickname = nickname;
    }

    QString email() {
        return m_email;
    }
    void setEmail(const QString& email) {
        m_email = email;
    }

    QString mobile() {
        return m_mobile;
    }
    void setMobile(const QString& mobile) {
        m_mobile = mobile;
    }

    int sex() {
        return m_sex;
    }
    void setSex(int sex) {
        m_sex = sex;
    }

    QString avatar() {
        return m_avatar;
    }
    void setAvatar(const QString& avatar) {
        m_avatar = avatar;
    }

    QString loginIp() {
        return m_loginIp;
    }
    void setLoginIp(const QString& loginIp) {
        m_loginIp = loginIp;
    }

    QString loginDate() {
        return m_loginDate;
    }
    void setLoginDate(const QString& loginDate) {
        m_loginDate = loginDate;
    }

    QString createTime() {
        return m_createTime;
    }
    void setCreateTime(const QString& createTime) {
        m_createTime = createTime;
    }

    QString roles() {
        return m_roles;
    }
    void setRoles(const QString& roles) {
        m_roles = roles;
    }

    QString dept() {
        return m_dept;
    }
    void setDept(const QString& dept) {
        m_dept = dept;
    }

    QString posts() {
        return m_posts;
    }
    void setPosts(const QString& posts) {
        m_posts = posts;
    }
signals:
    void signalUsernameChanged(const QString& username);
    void signalNicknameChanged(const QString& nickname);
    void signalMobileChanged(const QString& mobile);
    void signalEmailChanged(const QString& email);
    void signalSexChanged(int sex);
    void signalAvatarChanged(const QString& avatar);
private:
    int m_id;
    QString m_username;
    QString m_nickname;
    QString m_email;
    QString m_mobile;
    int m_sex;
    QString m_avatar;
    QString m_loginIp;
    QString m_loginDate;
    QString m_createTime;
    QString m_roles;
    QString m_dept;
    QString m_posts;
};
#endif // USERINFOMODEL_H
