// SPDX-FileCopyrightText: 2026 Marco Allegretti
// SPDX-License-Identifier: EUPL-1.2

#pragma once

#include <QObject>
#include <QString>
#include <qqmlregistration.h>

class QQmlEngine;
class QJSEngine;

class SetupState : public QObject
{
    Q_OBJECT
    QML_ELEMENT
    QML_SINGLETON

    Q_PROPERTY(QString deviceClass READ deviceClass WRITE setDeviceClass NOTIFY deviceClassChanged)
    Q_PROPERTY(QString experienceProfile READ experienceProfile WRITE setExperienceProfile NOTIFY experienceProfileChanged)
    Q_PROPERTY(QString primaryInput READ primaryInput WRITE setPrimaryInput NOTIFY primaryInputChanged)
    Q_PROPERTY(bool convergenceModeEnabled READ convergenceModeEnabled WRITE setConvergenceModeEnabled NOTIFY shellSettingsChanged)
    Q_PROPERTY(bool gamingModeEnabled READ gamingModeEnabled WRITE setGamingModeEnabled NOTIFY shellSettingsChanged)
    Q_PROPERTY(bool navigationPanelEnabled READ navigationPanelEnabled WRITE setNavigationPanelEnabled NOTIFY shellSettingsChanged)
    Q_PROPERTY(bool dynamicTilingEnabled READ dynamicTilingEnabled WRITE setDynamicTilingEnabled NOTIFY shellSettingsChanged)
    Q_PROPERTY(bool snapLayoutsEnabled READ snapLayoutsEnabled WRITE setSnapLayoutsEnabled NOTIFY shellSettingsChanged)
    Q_PROPERTY(bool autoHidePanelsEnabled READ autoHidePanelsEnabled WRITE setAutoHidePanelsEnabled NOTIFY shellSettingsChanged)

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

    static SetupState *self();
    static SetupState *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine);

    QString deviceClass() const;
    void setDeviceClass(const QString &deviceClass);

    QString experienceProfile() const;
    void setExperienceProfile(const QString &experienceProfile);

    QString primaryInput() const;
    void setPrimaryInput(const QString &primaryInput);

    bool convergenceModeEnabled() const;
    void setConvergenceModeEnabled(bool enabled);

    bool gamingModeEnabled() const;
    void setGamingModeEnabled(bool enabled);

    bool navigationPanelEnabled() const;
    void setNavigationPanelEnabled(bool enabled);

    bool dynamicTilingEnabled() const;
    void setDynamicTilingEnabled(bool enabled);

    bool snapLayoutsEnabled() const;
    void setSnapLayoutsEnabled(bool enabled);

    bool autoHidePanelsEnabled() const;
    void setAutoHidePanelsEnabled(bool enabled);

    Q_INVOKABLE void useRecommendedSettings();
    Q_INVOKABLE void applyDeviceDefaults(const QString &deviceClass, const QString &primaryInput);
    Q_INVOKABLE void applyExperienceDefaults(const QString &experienceProfile);
    void apply(bool applyToRunningSession = true);

Q_SIGNALS:
    void deviceClassChanged();
    void experienceProfileChanged();
    void primaryInputChanged();
    void shellSettingsChanged();

private:
    void emitShellSettingsChanged();

    QString m_deviceClass;
    QString m_experienceProfile;
    QString m_primaryInput;
    bool m_convergenceModeEnabled = false;
    bool m_gamingModeEnabled = false;
    bool m_navigationPanelEnabled = false;
    bool m_dynamicTilingEnabled = true;
    bool m_snapLayoutsEnabled = true;
    bool m_autoHidePanelsEnabled = false;
};
