/*
* Copyright (C) 2026, 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 AUTOTESTS_WINDOWS_STUB_QGSETTINGS
#define AUTOTESTS_WINDOWS_STUB_QGSETTINGS

#include <QByteArray>
#include <QHash>
#include <QObject>
#include <QStringList>
#include <QVariant>

class QGSettings : public QObject
{
public:
    explicit QGSettings(const QByteArray &schema, QObject *parent = nullptr)
        : QObject(parent),
          m_schema(QString::fromLatin1(schema))
    {
    }

    static bool isSchemaInstalled(const QByteArray &schema)
    {
        return s_installedSchemas.contains(QString::fromLatin1(schema));
    }

    static void installSchema(const QByteArray &schema, const QStringList &keys)
    {
        const QString schemaName = QString::fromLatin1(schema);
        s_installedSchemas.insert(schemaName, true);
        s_keys.insert(schemaName, keys);
    }

    static void setValue(const QByteArray &schema, const QString &key, const QVariant &value)
    {
        s_values[QString::fromLatin1(schema)].insert(key, value);
    }

    static void resetTestData()
    {
        s_installedSchemas.clear();
        s_keys.clear();
        s_values.clear();
    }

    QStringList keys() const
    {
        return s_keys.value(m_schema);
    }

    QVariant get(const QString &key) const
    {
        return s_values.value(m_schema).value(key);
    }

private:
    QString m_schema;
    inline static QHash<QString, bool> s_installedSchemas;
    inline static QHash<QString, QStringList> s_keys;
    inline static QHash<QString, QHash<QString, QVariant>> s_values;
};

#endif
