#pragma once

#include <optional>

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

#include "core/models/DataMapping.h"

namespace softbus::core::metadata
{

class ProfileRegistry
{
public:
    bool loadFromFile(const QString& filePath);
    const softbus::core::models::DeviceDataProfile* find(const QString& deviceId,
                                                          const QString& protocol) const;

    const QString& lastError() const { return m_lastError; }
    bool           empty() const { return m_profilesByKey.isEmpty(); }

private:
    static QString makeKey(const QString& deviceId, const QString& protocol);
    static std::optional<softbus::core::models::DataPointMapping> parseMapping(const QJsonObject& o);
    static softbus::core::models::DataType                        parseDataType(const QString& s);
    static softbus::core::models::Endianness                      parseEndianness(const QString& s);

private:
    QHash<QString, softbus::core::models::DeviceDataProfile> m_profilesByKey;
    QString                                                   m_lastError;
};

} // namespace softbus::core::metadata
