/*
 * Copyright 2025 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef UPDATENOTIFICATIONWIDGET_H
#define UPDATENOTIFICATIONWIDGET_H

#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QProgressBar>
#include <QTimer>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QTimerEvent>
#include <QDebug>
#include <QHostInfo>

#include <curl/curl.h>

#include "kaglobal.h"
#include "modeldownload.h"
#include "ktoolbutton.h"

using namespace  std;
using namespace kdk;

class UpdateNotificationWidget : public QWidget
{
    Q_OBJECT
public:
    enum UpdateState {
        NewVersionAvailable,
        LatestVersion,
        NetworkError
    };

    explicit UpdateNotificationWidget(PublicLocalModel &model, QWidget *parent = nullptr);

    void initLayout();
    void setUpdateState(UpdateState state);
    void resetProgressBar();
    bool getNetStatus();
    bool checkNetWorkOnline();
    void setCancelDownloadButtonVisible(bool isVisible);
    void setProgressBarVisible(bool isVisible);
    void setCancelDownloadButtenEnabled(bool isEnabled);
    QString getDownloadUrl();
public slots:
    void slUpdateProgressValue(int value);
    void slClickExitButton();
signals:
    void updateDownloadProgress(int value );
    void sigCancelDownload();
    void sigShowIsInstalling();
private:
private:
    QHBoxLayout *m_mainHLayout;
    QLabel *updateMessageLabel = nullptr;
    QLabel *noNewUpdateLabel = nullptr;
    QLabel *errorMessageLabel = nullptr;
    QLabel *restartEffectLabel = nullptr;
    QPushButton *m_pauseButton;
    QPushButton *m_closeButton;
    QProgressBar *m_progressBar;
    QToolButton *m_downloadButton = nullptr; // 下载

    int m_downloadProgress;
    UpdateState m_currentState;
    QString m_modelDebName;
    bool m_downloading;
    bool m_netStaus;
};

#endif // UPDATENOTIFICATIONWIDGET_H
