#pragma once
// 定义DOM消息
#include <cstdint>
#include <vector>
#include <variant>

#include <QString>
#include <QHash>
#include <QJsonValue>

#include "core/models/MetadataDef.h"
#include "core/models/Types.h"

namespace softbus::core::models
{

using DOMValue = std::variant<bool, std::int32_t, std::uint32_t, std::int64_t, float, double>;

class DOMMessage
{
public:
    DOMMessage() = default;

    QString            messageId;                     // 消息ID
    const MetadataDef* metaRef{nullptr};              // 元数据引用
    std::int64_t       timestamp{0};                   // 时间戳
    DOMValue           value{0.0};                     // 值
    DataQuality        quality{DataQuality::BAD};      // 质量
    QHash<QString, QJsonValue> attributes;              // 属性
    std::vector<QString>       traceLog;                // 跟踪日志

    DataDomain domain() const { return metaRef ? metaRef->domain : DataDomain::UNKNOWN; }

    template <typename T>
    T getValueAs() const
    {
        if (const auto* p = std::get_if<T>(&value)) {
            return *p;
        }
        return T{};
    }

    void appendTrace(const QString& log)
    {
        traceLog.push_back(log);
    }
};

} // namespace softbus::core::models
