// SPDX-FileCopyrightText: 2025 Prayag Jain <prayagjain2@gmail.com>
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include "libdrawywidgets_private_export.h"
#include <QWidget>
class RenderingContext;
class SpatialContext;
class UIContext;
class SelectionContext;
class MimeManager;

/**
 * @note: This class was made a Singleton recently, so in many places it is
 * still accessed by passing its pointer instead of using the `instance` method.
 */
class LIBDRAWYWIDGETS_TESTS_EXPORT ApplicationContext : public QObject
{
    Q_OBJECT
public:
    explicit ApplicationContext(QWidget *parent = nullptr);
    ~ApplicationContext() override;

    [[nodiscard]] QWidget *parentWidget() const;

    [[nodiscard]] RenderingContext *renderingContext() const;
    [[nodiscard]] SpatialContext *spatialContext() const;
    [[nodiscard]] UIContext *uiContext() const;
    [[nodiscard]] SelectionContext *selectionContext() const;
    [[nodiscard]] MimeManager *mimeManager() const;

    void reset(); // resets the canvas to a blank state

    [[nodiscard]] QString currentFileName() const;
    void setCurrentFileName(const QString &newCurrentFileName);
    [[nodiscard]] bool fileNeedsName() const;

    [[nodiscard]] bool currentFileModified() const;
    void setCurrentFileModified(bool value);

    [[nodiscard]] bool debug() const;
    void setDebug(bool newDebug);

Q_SIGNALS:
    void currentFileStateChanged();

private:
    [[nodiscard]] QString unsavedFileName() const;
    QString m_currentFileName;
    bool m_currentFileModified{false};
    bool m_fileHasName{false};

    QWidget *const m_parentWidget;

    RenderingContext *const m_renderingContext;
    SpatialContext *const m_spatialContext;
    UIContext *const m_uiContext;
    SelectionContext *const m_selectionContext;
    MimeManager *const m_mimeManager;
    bool mDebug = false;
};
