#pragma once

#include <optional>

#include <QHash>
#include <QJsonObject>
#include <QString>

#include "core/models/MetadataDef.h"

namespace softbus::core::metadata
{

class MetadataRegistry
{
public:
    bool loadFromFile(const QString& filePath);

    const softbus::core::models::MetadataDef* findById(const QString& metadataId) const;
    bool                                       empty() const { return m_defsById.isEmpty(); }
    const QString&                             lastError() const { return m_lastError; }

private:
    static std::optional<softbus::core::models::MetadataDef> parseOne(const QJsonObject& o);

private:
    QHash<QString, softbus::core::models::MetadataDef> m_defsById;
    QString                                             m_lastError;
};

} // namespace softbus::core::metadata
