#ifndef LOCALMODELITEM_H
#define LOCALMODELITEM_H

#include <QWidget>
#include <QGSettings>
#include <QMouseEvent>
#include <QMenu>
#include <QLabel>
#include <QVariant>
#include <QToolButton>
#include <QHBoxLayout>

#include "ktoolbutton.h"
#include "kaglobal.h"
#include <aiconfig/modelconfig.h>

#include "updatenotificationwidget.h"
#include "util.h"

#define THEME_QT_SCHEMA  "org.ukui.style"
#define TEMP_REBOOT_FILE "/tmp/temp_reboot_file.txt"
using namespace std;
using namespace kyai::config::model;

enum MessageTipType{
    InfoMessage =0x0,
    WarningMessage,
    PersistentMessage
};

class LocalModelItem :public QWidget
{
    Q_OBJECT
public:
    explicit LocalModelItem(PublicLocalModel model, SystemVersion curSystemVersion, QWidget *parent = nullptr);
    ~LocalModelItem();

    void showSelectedIcon(bool flag);
    bool isSelected();
    AiCapability getAICapability();
    QString getModelName();
    QString getModelDebName();
    bool getIsStartDownloading();
    void showMessageTips(MessageTipType type,const QString &msg,const int &duration);

private:
    void initModelDownloadLayout();
    void initLayout();
    void initMenu();
    void initInstallSuccessMsgBox();
    void initConnect();
signals:
    void sigEdit(AiCapability capability, QString modelName);
    void sigDelete(AiCapability capability, QString modelName);
public slots:
    void checkHasNewVersion();
    bool createRebootTempFile();
    bool checkHasRebootTempFile();
    void sldownModel();
    void startNetErrorTips();
    void slUpdateModelInstallStatus(int value,QString status ,QString details);
    void slUpdateModelInstallFinished(bool isSuccess,QStringList upgradeGroup,QString errorStr,QString errorDesc);
    void slUpdateCancelButton(bool isInstalling);
private:
    QHBoxLayout *m_mainHLayout;
    //模型名称
    QLabel *m_modelNameLabel;

    //模型面板
    QHBoxLayout *m_panelHLayout;
    //信息
    QHBoxLayout *m_messageHLayout;
    QWidget *m_messageWidget;
    QLabel *m_tipsLabel;
    QToolButton *m_moreButton = nullptr;  // 更多
    QToolButton *m_downButton = nullptr;  //下载
    KToolButton *m_loadButton = nullptr;  // 加载
    QMenu *m_menu;
    //下载进度条
    QHBoxLayout *m_progressHLayout;
    UpdateNotificationWidget *updateProgressBar =nullptr;
    //选择框
    QLabel *m_selectedIconLabel = nullptr;// 已选择状态
    //下载成功对话框
    QMessageBox *m_installSuccessMsgBox;

    //当前提示信息
    QString m_currentTipsMsg;
private:
    kyai::config::model::AiCapability m_capability;
    QString m_modelName;
    PublicLocalModel m_model;
    LocalModelInstallStatus m_modelStatus;
    bool isModelSelected;
    bool isDownLoading =false;
    bool isStartDownloading = false;
    QTimer *m_timer;

    QString m_currentInfoMessage = "";
    QString m_currentWarningMessage = "";

    QTimer* m_infoTimer = nullptr;
    QTimer* m_warningTimer = nullptr;

    SystemVersion m_curSystemVersion;
};

#endif // LOCALMODELITEM_H
