/*
 * UKUI Framework
 *
 * Copyright (C) 2024, KylinSoft Co., Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Authors: Yue Lan <lanyue@kylinos.cn>
 *
 */

#ifndef THEME_H
#define THEME_H

#include <QObject>
#include <QDBusContext>

class Theme : public QObject, protected QDBusContext
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.ukui.Framework.UI.Theme")
public:
    /**
     * @brief The ThemeMode enum
     * 主题模式，分为
     * 深色、浅色、深浅混合、自适应
     * 四种模式
     */
    enum ThemeModeEnum {
        Light,
        Dark,
        Mixed,
        SelfAdapted
    };
    Q_ENUM(ThemeModeEnum)

    explicit Theme(QObject *parent = nullptr);
    ~Theme();

public slots:
    /**
     * @brief isUserCustomed
     * 用户是否进行了主题自定义
     * @return
     * 是，用户修改过当前主题，如图标、壁纸等
     */
    Q_INVOKABLE bool IsUserCustomized();

    /**
     * @brief GetStyleThemeList
     * 获取支持的主题列表
     * @return
     * 主题列表，主题名称为非本地化主题名，
     * 例如"Light-Seeking"（寻光），
     * "HeYin"（和印），
     * "Classic"（启典）
     */
    Q_INVOKABLE QStringList GetStyleThemeList();

    /**
     * @brief SetStyleTheme
     * 设置主题，可选在GetStyleThemeList()中的主题
     * @param name
     * 主题名称，如"Light-Seeking"
     * @return
     * 设置成功/失败
     */
    Q_INVOKABLE bool SetStyleTheme(const QString &name);

    /**
     * @brief SetThemeMode
     * 设置主题模式
     * @param themeMode
     * @sa ThemeMode
     * @return
     * 设置成功/失败
     */
    Q_INVOKABLE bool SetThemeMode(int themeMode);

    /**
     * @brief SetAccentColor
     * 设置控件强调色
     * @param hexColor
     * 强调色，rgb hex格式
     * @return
     * 设置成功/失败
     */
    Q_INVOKABLE bool SetAccentColor(const QString &hexColor);

    /**
     * @brief GetIconThemeList
     * 获取支持的图标主题列表
     * @return
     * 如"ukui-icon-theme-default",
     * "ukui-icon-theme-fashion",
     * "ukui-icon-theme-classical"
     */
    Q_INVOKABLE QStringList GetIconThemeList();

    /**
     * @brief SetIconTheme
     * 设置主题图标
     * @param iconThemeName
     * 在主题图标列表中的主题图标名
     * @return
     * 设置成功/失败
     */
    Q_INVOKABLE bool SetIconTheme(const QString &iconThemeName);

    /**
     * @brief GetCursorThemeList
     * 获取光标主题列表
     * @return
     */
    Q_INVOKABLE QStringList GetCursorThemeList();

    /**
     * @brief SetCursorTheme
     * 设置声音主题
     * @param cursorThemeName
     * @return
     * 设置成功/失败
     */
    Q_INVOKABLE bool SetCursorTheme(const QString &cursorThemeName);

    /**
     * @brief GetSoundThemeList
     * 获取声音主题列表
     * @return
     */
    Q_INVOKABLE QStringList GetSoundThemeList();

    /**
     * @brief SetSoundThemeList
     * 设置声音主题
     * @param soundThemeName
     * @return
     * 设置成功/失败
     */
    Q_INVOKABLE bool SetSoundTheme(const QString &soundThemeName);

    /**
     * @brief SetWindowRadius
     * 设置窗口圆角
     * @param radius
     * @return
     * 设置成功/失败
     */
    Q_INVOKABLE bool SetWindowRadius(int newWindowRadius);

public:
    const QString &getGlobalThemeName() const;

    const QString &getQtStyleName() const;

    const QString &getGtkStyleName() const;

    const QString &getIconThemeName() const;

    const QString &getCursorThemeName() const;

    const QString &getSoundThemeName() const;

    int getWindowRadius() const;

    int getThemeMode() const;

signals:
    void ThemeModeChanged();

    void QtStyleNameChanged();

    void GtkStyleNameChanged();

    void IconThemeNameChanged();

    void CursorThemeNameChanged();

    void SoundThemeNameChanged();

    void GlobalThemeNameChanged();

    void WindowRadiusChanged();

    void UserCustomizedChanged();

private:
    void setUserModified(bool modified);

    QString GlobalThemeName;
    int ThemeMode = 0;
    QString QtStyleName;
    QString GtkStyleName;
    QString IconThemeName;
    QString CursorThemeName;
    QString SoundThemeName;
    int WindowRadius = 12;
    bool UserCustomized = false;

    Q_PROPERTY(QString GlobalThemeName READ getGlobalThemeName WRITE SetStyleTheme NOTIFY GlobalThemeNameChanged)
    Q_PROPERTY(int ThemeMode READ getThemeMode NOTIFY ThemeModeChanged)
    Q_PROPERTY(QString QtStyleName READ getQtStyleName NOTIFY QtStyleNameChanged)
    Q_PROPERTY(QString GtkStyleName READ getGtkStyleName NOTIFY GtkStyleNameChanged)
    Q_PROPERTY(QString IconThemeName READ getIconThemeName WRITE SetIconTheme NOTIFY IconThemeNameChanged)
    Q_PROPERTY(QString CursorThemeName READ getCursorThemeName WRITE SetCursorTheme NOTIFY CursorThemeNameChanged)
    Q_PROPERTY(QString SoundThemeName READ getSoundThemeName WRITE SetSoundTheme NOTIFY SoundThemeNameChanged)
    Q_PROPERTY(int WindowRadius READ getWindowRadius WRITE SetWindowRadius NOTIFY WindowRadiusChanged)
    Q_PROPERTY(bool UserCustomized READ IsUserCustomized NOTIFY UserCustomizedChanged)
};

#endif // THEME_H
