// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QOHOSAPPCONTEXT_H
#define QOHOSAPPCONTEXT_H

#include "qtohosextrasglobal.h"
#include <QtCore/qobject.h>
#include <QtCore/qsharedpointer.h>
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
#include <QtOhosExtras/qohosappbundleinfo.h>
#include <QtOhosExtras/qohosapppermissions.h>
#include <QtOhosExtras/qohoswant.h>

QT_BEGIN_NAMESPACE

namespace QtOhosExtras {

class Q_OHOS_EXTRAS_EXPORT QOhosAppContext : public QObject
{
    Q_OBJECT

public:
    using AppPermission = AppPermissions::Permission;

    enum class ColorThemeMode
    {
        LightTheme,
        DarkTheme,
        FollowSystemSetting,
    };
    Q_ENUM(ColorThemeMode)

    using AppPermissionResult = AppPermissions::PermissionResult;

    static QOhosAppContext *instance();

    static bool isNoUiChildMode();

    static void startNoUiChildProcess(QString libraryName, QStringList args);

    static QOhosWant getAppLaunchWant();
    static QSharedPointer<QOhosWantInfo> getAppLaunchWantInfo();

    virtual bool isPermissionGranted(AppPermissions::Permission permission) const = 0;
    virtual bool isPermissionGranted(const QString &permissionName) const = 0;

    virtual void requestPermissionFromUserIfNeeded(AppPermissions::Permission permission) = 0;

    virtual void requestPermissionOnSettingIfNeeded(AppPermissions::Permission permission) = 0;

    virtual double fontSizeScale() const = 0;

    virtual bool darkThemeActive() const = 0;

    virtual void setColorThemeMode(ColorThemeMode mode) = 0;

    virtual void enableContextMenuEventOnLongPress() = 0;

    virtual QSharedPointer<QOhosBundleInfo> getBundleInfo() const = 0;

    virtual Q_NORETURN void restartApp() = 0;

    virtual Q_NORETURN void restartApp(const QOhosWant &want) = 0;

Q_SIGNALS:
    void permissionRequestResponseReceived(AppPermissions::Permission permission, bool permissionGranted);

    void permissionRequestResponseWithResultReceived(AppPermissions::Permission permission, AppPermissions::PermissionResult result);

    void permissionRequestOnSettingResponseReceived(AppPermissions::Permission permission, bool permissionGranted);
    
    void fontSizeScaleChanged(double fontSizeScale);

    void darkThemeActiveChanged(bool darkThemeActive);

protected:
    QOhosAppContext();
    ~QOhosAppContext() override;

    Q_DISABLE_COPY(QOhosAppContext)
};

}

QT_END_NAMESPACE

#endif
