/*
 * SPDX-FileCopyrightText: 2026 ChromiumOS-Guy <chromiumos-guy-opensource@proton.me>
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#pragma once

#include <QObject>
#include <QString>
#include <QStringList>
#include <QVariantMap>
#include <QDBusVariant>
#include <QDBusContext>
#include <QFileSystemWatcher>

#include "PortalInterface.h"

namespace portals {

class Settings : public QObject, protected QDBusContext
{
    Q_OBJECT
    Q_PROPERTY(uint version READ version CONSTANT)

public:
    explicit Settings(QObject *parent = nullptr);

signals:
    void SettingChanged(const QString &ns, const QString &key, const QDBusVariant &value);

public slots:
    QDBusVariant Read(const QString &ns, const QString &key);
    QMap<QString, QVariantMap> ReadAll(const QStringList &namespaces);

private slots:
    void handleThemeChange(const QString &path);

private:
    // Values match the org.freedesktop.appearance color-scheme spec.
    enum ColorScheme : uint {
        NoPreference = 0,
        PreferDark = 1,
        PreferWhite = 2,
    };

    uint version() const { return 1; }
    ColorScheme getLomiriColorScheme();
    QVariantMap appearanceSettings();

    const QString m_configPath;
    QFileSystemWatcher *m_watcher;
    uint m_lastColorScheme;
    
};

} // namespace portals

LOMIRI_PORTAL_PLUGIN(Settings)
