/*
    SPDX-FileCopyrightText: 2023-2026 Laurent Montel <montel@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later

*/
#pragma once
#include "kdebugsettingsloadingcategories.h"
#include "libkdebugsettingscore_export.h"
#include "model/categorytypemodel.h"
#include "model/customloggingcategorymodel.h"
#include "model/customloggingcategoryproxymodel.h"
#include "model/kdeapplicationloggingcategorymodel.h"
#include "model/kdeapplicationloggingcategoryproxymodel.h"
#include <QObject>
class LIBKDEBUGSETTINGSCORE_EXPORT LoggingManager : public QObject
{
    Q_OBJECT
    Q_PROPERTY(CustomLoggingCategoryModel *customCategoryModel READ customCategoryModel CONSTANT)
    Q_PROPERTY(CustomLoggingCategoryProxyModel *customLoggingCategoryProxyModel READ customLoggingCategoryProxyModel CONSTANT)
    Q_PROPERTY(KDEApplicationLoggingCategoryModel *qtKdeCategoryModel READ qtKdeCategoryModel CONSTANT)
    Q_PROPERTY(KDEApplicationLoggingCategoryProxyModel *kdeApplicationLoggingCategoryProxyModel READ kdeApplicationLoggingCategoryProxyModel CONSTANT)
    Q_PROPERTY(CategoryTypeModel *categoryTypeModel READ categoryTypeModel CONSTANT)
    Q_PROPERTY(bool foundOverrideRule READ foundOverrideRule CONSTANT)

public:
    static LoggingManager &self();

    ~LoggingManager() override;

    [[nodiscard]] CustomLoggingCategoryModel *customCategoryModel() const;

    [[nodiscard]] KDEApplicationLoggingCategoryModel *qtKdeCategoryModel() const;

    [[nodiscard]] CategoryTypeModel *categoryTypeModel() const;

    [[nodiscard]] Q_INVOKABLE QString environmentrules() const;

    [[nodiscard]] bool foundOverrideRule() const;

    void readCategoriesFiles(const QString &path);

    [[nodiscard]] KdeLoggingCategory::List categoriesList() const;

    void readQtLoggingFile();
    void updateLoggingCategories();

    [[nodiscard]] Q_INVOKABLE bool saveInQtLogging();

    [[nodiscard]] Q_INVOKABLE bool saveRules(const QString &path, bool forceSavingAllRules = false);

    [[nodiscard]] KDEApplicationLoggingCategoryProxyModel *kdeApplicationLoggingCategoryProxyModel() const;

    [[nodiscard]] CustomLoggingCategoryProxyModel *customLoggingCategoryProxyModel() const;

private:
    LIBKDEBUGSETTINGSCORE_NO_EXPORT explicit LoggingManager(QObject *parent = nullptr);
    CustomLoggingCategoryModel *const mCustomCategoryModel;
    CustomLoggingCategoryProxyModel *const mCustomLoggingCategoryProxyModel;
    KDEApplicationLoggingCategoryModel *const mQtKdeCategoryModel;
    CategoryTypeModel *const mCategoryTypeModel;
    KDEApplicationLoggingCategoryProxyModel *const mKdeApplicationLoggingCategoryProxyModel;
    KDebugSettingsLoadingCategories mLoggings;
};
