#pragma once

#include <cstdint>
#include <nlohmann/json.hpp>
#include <string>

namespace softbus::core {

enum class DomDomain : uint8_t {
    Process = 0,
    Control = 1,
    Monitor = 2,
    Management = 3
};

enum class QualityCode : int {
    Good = 0,
    Bad = 1,
    Timeout = 2,
    Overflow = 3
};

struct DOMMessage {
    std::string traceId;
    std::string id;
    std::string sourceId;
    int64_t timestampNs{0};
    DomDomain domain{DomDomain::Process};
    QualityCode quality{QualityCode::Good};
    nlohmann::json value;

    nlohmann::json toJson() const
    {
        return nlohmann::json{
            {"traceId", traceId},
            {"id", id},
            {"sourceId", sourceId},
            {"timestampNs", timestampNs},
            {"domain", static_cast<int>(domain)},
            {"quality", static_cast<int>(quality)},
            {"value", value}
        };
    }

    static DOMMessage fromJson(const nlohmann::json& j)
    {
        DOMMessage msg;
        msg.traceId = j.value("traceId", "");
        msg.id = j.value("id", "");
        msg.sourceId = j.value("sourceId", "");
        msg.timestampNs = j.value("timestampNs", int64_t{0});
        msg.domain = static_cast<DomDomain>(j.value("domain", 0));
        msg.quality = static_cast<QualityCode>(j.value("quality", 0));
        if (j.contains("value")) {
            msg.value = j["value"];
        }
        return msg;
    }
};

} // namespace softbus::core
