/**
 * This file is generated by dconfig2cpp.
 * Command line arguments: /usr/lib/dtk6/DCore/bin/dconfig2cpp -o /build/treeland/src/treeland/build/src/outputconfig.hpp -c OutputConfig /build/treeland/src/treeland/misc/dconfig/org.deepin.dde.treeland.output.json
 * Generation time: 2026-08-18T12:51:56
 * JSON file version: 1.0
 * Tool version: 1.1
 *
 * WARNING: DO NOT MODIFY THIS FILE MANUALLY.
 * If you need to change the content, please modify the dconfig2cpp tool.
 */

#ifndef OUTPUTCONFIG_H
#define OUTPUTCONFIG_H

#define OUTPUTCONFIG_DCONFIG_FILE_VERSION_MAJOR 1
#define OUTPUTCONFIG_DCONFIG_FILE_VERSION_MINOR 1
#define OUTPUTCONFIG_DCONFIG_FILE_adaptiveSyncEnabled
#define OUTPUTCONFIG_DCONFIG_FILE_brightness
#define OUTPUTCONFIG_DCONFIG_FILE_colorTemperature
#define OUTPUTCONFIG_DCONFIG_FILE_height
#define OUTPUTCONFIG_DCONFIG_FILE_refresh
#define OUTPUTCONFIG_DCONFIG_FILE_scale
#define OUTPUTCONFIG_DCONFIG_FILE_transform
#define OUTPUTCONFIG_DCONFIG_FILE_width
#define OUTPUTCONFIG_DCONFIG_FILE_x
#define OUTPUTCONFIG_DCONFIG_FILE_y

#include <QThread>
#include <QVariant>
#include <QPointer>
#include <QDebug>
#include <QAtomicPointer>
#include <QAtomicInteger>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QProperty>
#endif
#include <QEvent>
#include <DSGApplication>
#include <DConfig>

class OutputConfig : public QObject {
    Q_OBJECT

    Q_PROPERTY(bool adaptiveSyncEnabled READ adaptiveSyncEnabled WRITE setAdaptiveSyncEnabled NOTIFY adaptiveSyncEnabledChanged RESET resetAdaptiveSyncEnabled)
    Q_PROPERTY(double brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged RESET resetBrightness)
    Q_PROPERTY(qlonglong colorTemperature READ colorTemperature WRITE setColorTemperature NOTIFY colorTemperatureChanged RESET resetColorTemperature)
    Q_PROPERTY(qlonglong height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight)
    Q_PROPERTY(qlonglong refresh READ refresh WRITE setRefresh NOTIFY refreshChanged RESET resetRefresh)
    Q_PROPERTY(double scale READ scale WRITE setScale NOTIFY scaleChanged RESET resetScale)
    Q_PROPERTY(qlonglong transform READ transform WRITE setTransform NOTIFY transformChanged RESET resetTransform)
    Q_PROPERTY(qlonglong width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth)
    Q_PROPERTY(qlonglong x READ x WRITE setX NOTIFY xChanged RESET resetX)
    Q_PROPERTY(qlonglong y READ y WRITE setY NOTIFY yChanged RESET resetY)
    Q_CLASSINFO("DConfigKeyList", "adaptiveSyncEnabled;brightness;colorTemperature;height;refresh;scale;transform;width;x;y")
    Q_CLASSINFO("DConfigFileName", "org.deepin.dde.treeland.output")
    Q_CLASSINFO("DConfigFileVersion", "1.0")

public:
    explicit OutputConfig(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend,
                        const QString &name, const QString &appId, const QString &subpath,
                        bool isGeneric, QObject *parent)
                  : QObject(parent), m_data(new Data) {
        m_data->m_userConfig = this;
        m_data->moveToThread(this->thread());

        if (!thread->isRunning()) {
            qWarning() << QLatin1String("Warning: The provided thread is not running.");
        }
        Q_ASSERT(QThread::currentThread() != thread);
        auto worker = new QObject();
        worker->moveToThread(thread);

        QPointer<Data> safeData(m_data);

        QMetaObject::invokeMethod(worker, [safeData, backend, name, appId, subpath, isGeneric, worker]() mutable {
            delete worker;
            worker = nullptr;

            if (!safeData->m_status.testAndSetOrdered(static_cast<int>(Data::Status::Invalid),
                                                      static_cast<int>(Data::Status::Initializing))) {
                // CAS failed: status changed (e.g., set to Destroyed by destructor)
                // Schedule deletion of Data object via deleteLater to avoid direct delete in Config thread
                safeData->deleteLater();
                return;
            }

            DTK_CORE_NAMESPACE::DConfig *config = nullptr;
            if (isGeneric) {
                if (backend) {
                    config = DTK_CORE_NAMESPACE::DConfig::createGeneric(backend, name, subpath, nullptr);
                } else {
                    config = DTK_CORE_NAMESPACE::DConfig::createGeneric(name, subpath, nullptr);
                }
            } else {
                if (backend) {
                    if (appId.isNull()) {
                        config = DTK_CORE_NAMESPACE::DConfig::create(backend, DTK_CORE_NAMESPACE::DSGApplication::id(),
                                                                     name, subpath, nullptr);
                    } else {
                        config = DTK_CORE_NAMESPACE::DConfig::create(backend, appId, name, subpath, nullptr);
                    }
                } else {
                    if (appId.isNull()) {
                        config = DTK_CORE_NAMESPACE::DConfig::create(DTK_CORE_NAMESPACE::DSGApplication::id(),
                                                                     name, subpath, nullptr);
                    } else {
                        config = DTK_CORE_NAMESPACE::DConfig::create(appId, name, subpath, nullptr);
                    }
                }
            }

            if (!config || !config->isValid()) {
                qWarning() << QLatin1String("Failed to create DConfig instance.");

                QMetaObject::invokeMethod(safeData, [safeData]() {
                    if (safeData->m_status.testAndSetOrdered(static_cast<int>(Data::Status::Initializing),
                                                             static_cast<int>(Data::Status::Failed))) {
                        Q_EMIT safeData->m_userConfig->configInitializeFailed();
                    } else {
                        // CAS failed, destroy data object
                        delete safeData;
                    }
                }, Qt::QueuedConnection);

                if (config)
                    delete config;

                return;
            }
            config->moveToThread(QThread::currentThread());
            // Initialize through Data class
            safeData->initializeInConfigThread(config);

            // Queue state transition to main thread, to ensure config values are fully initialized.
            QMetaObject::invokeMethod(safeData, [safeData, config]() {
                // Try to transition from Initializing to Succeeded
                if (safeData->m_status.testAndSetOrdered(static_cast<int>(Data::Status::Initializing),
                                                         static_cast<int>(Data::Status::Succeeded))) {
                    // CAS succeeded: connect config destroyed signal to cleanup Data, then emit success signal to main thread
                    QObject::connect(config, &QObject::destroyed, safeData, &QObject::deleteLater);
                    if (safeData->m_userConfig) {
                        Q_EMIT safeData->m_userConfig->configInitializeSucceed(config);
                    }
                } else {
                    // CAS failed - state changed (e.g., set to Destroyed)
                    // We must clean up the config we just created
                    config->deleteLater();
                    safeData->deleteLater();
                }
            }, Qt::QueuedConnection);
        });
    }
    static OutputConfig* create(const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new OutputConfig(thread, nullptr, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0064\u0065\u002e\u0074\u0072\u0065\u0065\u006c\u0061\u006e\u0064\u002e\u006f\u0075\u0074\u0070\u0075\u0074"), appId, subpath, false, parent); }
    static OutputConfig* create(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new OutputConfig(thread, backend, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0064\u0065\u002e\u0074\u0072\u0065\u0065\u006c\u0061\u006e\u0064\u002e\u006f\u0075\u0074\u0070\u0075\u0074"), appId, subpath, false, parent); }
    static OutputConfig* createByName(const QString &name, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new OutputConfig(thread, nullptr, name, appId, subpath, false, parent); }
    static OutputConfig* createByName(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new OutputConfig(thread, backend, name, appId, subpath, false, parent); }
    static OutputConfig* createGeneric(const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new OutputConfig(thread, nullptr, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0064\u0065\u002e\u0074\u0072\u0065\u0065\u006c\u0061\u006e\u0064\u002e\u006f\u0075\u0074\u0070\u0075\u0074"), {}, subpath, true, parent); }
    static OutputConfig* create(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new OutputConfig(thread, backend, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0064\u0065\u002e\u0074\u0072\u0065\u0065\u006c\u0061\u006e\u0064\u002e\u006f\u0075\u0074\u0070\u0075\u0074"), {}, subpath, true, parent); }
    static OutputConfig* createGenericByName(const QString &name, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new OutputConfig(thread, nullptr, name, {}, subpath, true, parent); }
    static OutputConfig* createGenericByName(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
    { return new OutputConfig(thread, backend, name, {}, subpath, true, parent); }
    ~OutputConfig() {
        m_data->m_userConfig = nullptr;
        int oldStatus = m_data->m_status.fetchAndStoreOrdered(static_cast<int>(Data::Status::Destroyed));
        if (oldStatus == static_cast<int>(Data::Status::Succeeded)) {
            // When Succeeded, release config object only
            auto config = m_data->m_config.loadRelaxed();
            Q_ASSERT(config);
            config->deleteLater();
            // m_data will be deleted by config's destroyed signal
        } else if (oldStatus == static_cast<int>(Data::Status::Failed)) {
            // When Failed state, schedule cleanup of Data object
            m_data->deleteLater();
        }
    }

    Q_INVOKABLE DTK_CORE_NAMESPACE::DConfig *config() const {
        return m_data->m_config.loadRelaxed();
    }
    // Deprecated: Use isInitializeSucceeded() instead
    Q_INVOKABLE Q_DECL_DEPRECATED_X("Use isInitializeSucceeded() instead")
    bool isInitializeSucceed() const {
        return isInitializeSucceeded();
    }
    Q_INVOKABLE bool isInitializeSucceeded() const {
        return m_data->m_status.loadRelaxed() == static_cast<int>(Data::Status::Succeeded);
    }
    Q_INVOKABLE bool isInitializeFailed() const {
        return m_data->m_status.loadRelaxed() == static_cast<int>(Data::Status::Failed);
    }
    Q_INVOKABLE bool isInitializing() const {
        return m_data->m_status.loadRelaxed() == static_cast<int>(Data::Status::Initializing);
    }

    Q_INVOKABLE QStringList keyList() const {
        return { QStringLiteral("adaptiveSyncEnabled"),
                 QStringLiteral("brightness"),
                 QStringLiteral("colorTemperature"),
                 QStringLiteral("height"),
                 QStringLiteral("refresh"),
                 QStringLiteral("scale"),
                 QStringLiteral("transform"),
                 QStringLiteral("width"),
                 QStringLiteral("x"),
                 QStringLiteral("y")};
    }

    Q_INVOKABLE bool isDefaultValue(const QString &key) const {
        if (key == QStringLiteral("adaptiveSyncEnabled"))
            return adaptiveSyncEnabledIsDefaultValue();
        if (key == QStringLiteral("brightness"))
            return brightnessIsDefaultValue();
        if (key == QStringLiteral("colorTemperature"))
            return colorTemperatureIsDefaultValue();
        if (key == QStringLiteral("height"))
            return heightIsDefaultValue();
        if (key == QStringLiteral("refresh"))
            return refreshIsDefaultValue();
        if (key == QStringLiteral("scale"))
            return scaleIsDefaultValue();
        if (key == QStringLiteral("transform"))
            return transformIsDefaultValue();
        if (key == QStringLiteral("width"))
            return widthIsDefaultValue();
        if (key == QStringLiteral("x"))
            return xIsDefaultValue();
        if (key == QStringLiteral("y"))
            return yIsDefaultValue();
        return false;
    }

    bool adaptiveSyncEnabled() const {
        return m_data->p_adaptiveSyncEnabled;
    }
    void setAdaptiveSyncEnabled(const bool &value) {
        auto oldValue = m_data->p_adaptiveSyncEnabled;
        m_data->p_adaptiveSyncEnabled = value;
        m_data->markPropertySet(0);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("adaptiveSyncEnabled"), value);
            });
        }
        if (m_data->p_adaptiveSyncEnabled != oldValue) {
            Q_EMIT adaptiveSyncEnabledChanged();
            Q_EMIT valueChanged(QStringLiteral("adaptiveSyncEnabled"), value);
        }
    }
    void resetAdaptiveSyncEnabled() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("adaptiveSyncEnabled"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<bool> bindableAdaptiveSyncEnabled() {
        return QBindable<bool>(this, "adaptiveSyncEnabled");
    }
#endif
    Q_INVOKABLE bool adaptiveSyncEnabledIsDefaultValue() const {
        return !m_data->testPropertySet(0);
    }
    double brightness() const {
        return m_data->p_brightness;
    }
    void setBrightness(const double &value) {
        auto oldValue = m_data->p_brightness;
        m_data->p_brightness = value;
        m_data->markPropertySet(1);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("brightness"), value);
            });
        }
        if (m_data->p_brightness != oldValue) {
            Q_EMIT brightnessChanged();
            Q_EMIT valueChanged(QStringLiteral("brightness"), value);
        }
    }
    void resetBrightness() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("brightness"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<double> bindableBrightness() {
        return QBindable<double>(this, "brightness");
    }
#endif
    Q_INVOKABLE bool brightnessIsDefaultValue() const {
        return !m_data->testPropertySet(1);
    }
    qlonglong colorTemperature() const {
        return m_data->p_colorTemperature;
    }
    void setColorTemperature(const qlonglong &value) {
        auto oldValue = m_data->p_colorTemperature;
        m_data->p_colorTemperature = value;
        m_data->markPropertySet(2);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("colorTemperature"), value);
            });
        }
        if (m_data->p_colorTemperature != oldValue) {
            Q_EMIT colorTemperatureChanged();
            Q_EMIT valueChanged(QStringLiteral("colorTemperature"), value);
        }
    }
    void resetColorTemperature() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("colorTemperature"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableColorTemperature() {
        return QBindable<qlonglong>(this, "colorTemperature");
    }
#endif
    Q_INVOKABLE bool colorTemperatureIsDefaultValue() const {
        return !m_data->testPropertySet(2);
    }
    qlonglong height() const {
        return m_data->p_height;
    }
    void setHeight(const qlonglong &value) {
        auto oldValue = m_data->p_height;
        m_data->p_height = value;
        m_data->markPropertySet(3);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("height"), value);
            });
        }
        if (m_data->p_height != oldValue) {
            Q_EMIT heightChanged();
            Q_EMIT valueChanged(QStringLiteral("height"), value);
        }
    }
    void resetHeight() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("height"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableHeight() {
        return QBindable<qlonglong>(this, "height");
    }
#endif
    Q_INVOKABLE bool heightIsDefaultValue() const {
        return !m_data->testPropertySet(3);
    }
    qlonglong refresh() const {
        return m_data->p_refresh;
    }
    void setRefresh(const qlonglong &value) {
        auto oldValue = m_data->p_refresh;
        m_data->p_refresh = value;
        m_data->markPropertySet(4);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("refresh"), value);
            });
        }
        if (m_data->p_refresh != oldValue) {
            Q_EMIT refreshChanged();
            Q_EMIT valueChanged(QStringLiteral("refresh"), value);
        }
    }
    void resetRefresh() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("refresh"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableRefresh() {
        return QBindable<qlonglong>(this, "refresh");
    }
#endif
    Q_INVOKABLE bool refreshIsDefaultValue() const {
        return !m_data->testPropertySet(4);
    }
    double scale() const {
        return m_data->p_scale;
    }
    void setScale(const double &value) {
        auto oldValue = m_data->p_scale;
        m_data->p_scale = value;
        m_data->markPropertySet(5);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("scale"), value);
            });
        }
        if (m_data->p_scale != oldValue) {
            Q_EMIT scaleChanged();
            Q_EMIT valueChanged(QStringLiteral("scale"), value);
        }
    }
    void resetScale() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("scale"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<double> bindableScale() {
        return QBindable<double>(this, "scale");
    }
#endif
    Q_INVOKABLE bool scaleIsDefaultValue() const {
        return !m_data->testPropertySet(5);
    }
    qlonglong transform() const {
        return m_data->p_transform;
    }
    void setTransform(const qlonglong &value) {
        auto oldValue = m_data->p_transform;
        m_data->p_transform = value;
        m_data->markPropertySet(6);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("transform"), value);
            });
        }
        if (m_data->p_transform != oldValue) {
            Q_EMIT transformChanged();
            Q_EMIT valueChanged(QStringLiteral("transform"), value);
        }
    }
    void resetTransform() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("transform"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableTransform() {
        return QBindable<qlonglong>(this, "transform");
    }
#endif
    Q_INVOKABLE bool transformIsDefaultValue() const {
        return !m_data->testPropertySet(6);
    }
    qlonglong width() const {
        return m_data->p_width;
    }
    void setWidth(const qlonglong &value) {
        auto oldValue = m_data->p_width;
        m_data->p_width = value;
        m_data->markPropertySet(7);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("width"), value);
            });
        }
        if (m_data->p_width != oldValue) {
            Q_EMIT widthChanged();
            Q_EMIT valueChanged(QStringLiteral("width"), value);
        }
    }
    void resetWidth() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("width"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableWidth() {
        return QBindable<qlonglong>(this, "width");
    }
#endif
    Q_INVOKABLE bool widthIsDefaultValue() const {
        return !m_data->testPropertySet(7);
    }
    qlonglong x() const {
        return m_data->p_x;
    }
    void setX(const qlonglong &value) {
        auto oldValue = m_data->p_x;
        m_data->p_x = value;
        m_data->markPropertySet(8);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("x"), value);
            });
        }
        if (m_data->p_x != oldValue) {
            Q_EMIT xChanged();
            Q_EMIT valueChanged(QStringLiteral("x"), value);
        }
    }
    void resetX() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("x"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableX() {
        return QBindable<qlonglong>(this, "x");
    }
#endif
    Q_INVOKABLE bool xIsDefaultValue() const {
        return !m_data->testPropertySet(8);
    }
    qlonglong y() const {
        return m_data->p_y;
    }
    void setY(const qlonglong &value) {
        auto oldValue = m_data->p_y;
        m_data->p_y = value;
        m_data->markPropertySet(9);
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config, value]() {
                config->setValue(QStringLiteral("y"), value);
            });
        }
        if (m_data->p_y != oldValue) {
            Q_EMIT yChanged();
            Q_EMIT valueChanged(QStringLiteral("y"), value);
        }
    }
    void resetY() {
        if (auto config = m_data->m_config.loadRelaxed()) {
            QMetaObject::invokeMethod(config, [config]() {
                config->reset(QStringLiteral("y"));
            });
        }
    }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    QBindable<qlonglong> bindableY() {
        return QBindable<qlonglong>(this, "y");
    }
#endif
    Q_INVOKABLE bool yIsDefaultValue() const {
        return !m_data->testPropertySet(9);
    }
protected:
    bool event(QEvent *e) override {
        if (e->type() == QEvent::ThreadChange) {
            Q_ASSERT(this->thread() == m_data->thread());
        }
        return QObject::event(e);
    }
Q_SIGNALS:
    void configInitializeFailed();
    void configInitializeSucceed(DTK_CORE_NAMESPACE::DConfig *config);
    void valueChanged(const QString &key, const QVariant &value);
    void adaptiveSyncEnabledChanged();
    void brightnessChanged();
    void colorTemperatureChanged();
    void heightChanged();
    void refreshChanged();
    void scaleChanged();
    void transformChanged();
    void widthChanged();
    void xChanged();
    void yChanged();

private:
    // Prevent external moveToThread calls
    using QObject::moveToThread;
    class Data : public QObject {
    public:
        enum class Status {
            Invalid = 0,
            Initializing = 1,
            Succeeded = 2,
            Failed = 3,
            Destroyed = 4
        };

        explicit Data()
            : QObject(nullptr) {}

        inline void initializeInConfigThread(DTK_CORE_NAMESPACE::DConfig *config) {
            Q_ASSERT(!m_config.loadRelaxed());
            m_config.storeRelaxed(config);
            if (testPropertySet(0)) {
                config->setValue(QStringLiteral("adaptiveSyncEnabled"), QVariant::fromValue(p_adaptiveSyncEnabled));
            } else {
                updateValue(QStringLiteral("adaptiveSyncEnabled"), QVariant::fromValue(p_adaptiveSyncEnabled));
            }
            if (testPropertySet(1)) {
                config->setValue(QStringLiteral("brightness"), QVariant::fromValue(p_brightness));
            } else {
                updateValue(QStringLiteral("brightness"), QVariant::fromValue(p_brightness));
            }
            if (testPropertySet(2)) {
                config->setValue(QStringLiteral("colorTemperature"), QVariant::fromValue(p_colorTemperature));
            } else {
                updateValue(QStringLiteral("colorTemperature"), QVariant::fromValue(p_colorTemperature));
            }
            if (testPropertySet(3)) {
                config->setValue(QStringLiteral("height"), QVariant::fromValue(p_height));
            } else {
                updateValue(QStringLiteral("height"), QVariant::fromValue(p_height));
            }
            if (testPropertySet(4)) {
                config->setValue(QStringLiteral("refresh"), QVariant::fromValue(p_refresh));
            } else {
                updateValue(QStringLiteral("refresh"), QVariant::fromValue(p_refresh));
            }
            if (testPropertySet(5)) {
                config->setValue(QStringLiteral("scale"), QVariant::fromValue(p_scale));
            } else {
                updateValue(QStringLiteral("scale"), QVariant::fromValue(p_scale));
            }
            if (testPropertySet(6)) {
                config->setValue(QStringLiteral("transform"), QVariant::fromValue(p_transform));
            } else {
                updateValue(QStringLiteral("transform"), QVariant::fromValue(p_transform));
            }
            if (testPropertySet(7)) {
                config->setValue(QStringLiteral("width"), QVariant::fromValue(p_width));
            } else {
                updateValue(QStringLiteral("width"), QVariant::fromValue(p_width));
            }
            if (testPropertySet(8)) {
                config->setValue(QStringLiteral("x"), QVariant::fromValue(p_x));
            } else {
                updateValue(QStringLiteral("x"), QVariant::fromValue(p_x));
            }
            if (testPropertySet(9)) {
                config->setValue(QStringLiteral("y"), QVariant::fromValue(p_y));
            } else {
                updateValue(QStringLiteral("y"), QVariant::fromValue(p_y));
            }
            connect(config, &DTK_CORE_NAMESPACE::DConfig::valueChanged, this, [this](const QString &key) {
                updateValue(key);
            }, Qt::DirectConnection);
        }

        inline void updateValue(const QString &key, const QVariant &fallback = QVariant()) {
            if (!m_config.loadRelaxed())
                return;
            Q_ASSERT(QThread::currentThread() == m_config.loadRelaxed()->thread());
            const QVariant &value = m_config.loadRelaxed()->value(key, fallback);
            if (key == QStringLiteral("adaptiveSyncEnabled")) {
                markPropertySet(0, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<bool>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_adaptiveSyncEnabled != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_adaptiveSyncEnabled = newValue;
                        Q_EMIT m_userConfig->adaptiveSyncEnabledChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("brightness")) {
                markPropertySet(1, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<double>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_brightness != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_brightness = newValue;
                        Q_EMIT m_userConfig->brightnessChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("colorTemperature")) {
                markPropertySet(2, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_colorTemperature != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_colorTemperature = newValue;
                        Q_EMIT m_userConfig->colorTemperatureChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("height")) {
                markPropertySet(3, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_height != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_height = newValue;
                        Q_EMIT m_userConfig->heightChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("refresh")) {
                markPropertySet(4, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_refresh != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_refresh = newValue;
                        Q_EMIT m_userConfig->refreshChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("scale")) {
                markPropertySet(5, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<double>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_scale != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_scale = newValue;
                        Q_EMIT m_userConfig->scaleChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("transform")) {
                markPropertySet(6, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_transform != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_transform = newValue;
                        Q_EMIT m_userConfig->transformChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("width")) {
                markPropertySet(7, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_width != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_width = newValue;
                        Q_EMIT m_userConfig->widthChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("x")) {
                markPropertySet(8, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_x != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_x = newValue;
                        Q_EMIT m_userConfig->xChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
            if (key == QStringLiteral("y")) {
                markPropertySet(9, !m_config.loadRelaxed()->isDefaultValue(key));
                auto newValue = qvariant_cast<qlonglong>(value);
                QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
                    if (m_userConfig && p_y != newValue) {
                        Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
                        p_y = newValue;
                        Q_EMIT m_userConfig->yChanged();
                        Q_EMIT m_userConfig->valueChanged(key, value);
                    }
                });
                return;
            }
        }
        inline void markPropertySet(const int index, bool on = true) {
            if (index < 32) {
                if (on)
                    m_propertySetStatus0.fetchAndOrOrdered(1 << (index - 0));
                else
                    m_propertySetStatus0.fetchAndAndOrdered(~(1 << (index - 0)));
                return;
            }
            Q_UNREACHABLE();
        }
        inline bool testPropertySet(const int index) const {
            if (index < 32) {
                return (m_propertySetStatus0.loadRelaxed() & (1 << (index - 0)));
            }
            Q_UNREACHABLE();
        }
        // Member variables
        QAtomicPointer<DTK_CORE_NAMESPACE::DConfig> m_config = nullptr;
        QAtomicInteger<int> m_status = static_cast<int>(Status::Invalid);
        QPointer<OutputConfig> m_userConfig = nullptr;
        QAtomicInteger<quint32> m_propertySetStatus0 = 0;

        // Property storage
        bool p_adaptiveSyncEnabled { false };
        double p_brightness { 1 };
        qlonglong p_colorTemperature { 6600 };
        qlonglong p_height { 0 };
        qlonglong p_refresh { 0 };
        double p_scale { 1 };
        qlonglong p_transform { 0 };
        qlonglong p_width { 0 };
        qlonglong p_x { 0 };
        qlonglong p_y { 0 };
    };

    QPointer<Data> m_data;
};

#endif // OUTPUTCONFIG_H
