#pragma once

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

namespace softbus::core {

enum class SoftbusQuality {
    Good,
    Bad,
    Uncertain,
    OutOfRange,
    Stale
};

enum class SignalType {
    AI,
    AO,
    DI,
    DO,
    Unknown
};

enum class PointAccess {
    Read,
    Write,
    ReadWrite
};

struct SoftbusDataPoint {
    std::string deviceId;
    std::string pointId;
    double value{0.0};
    std::string unit;
    SoftbusQuality quality{SoftbusQuality::Good};
    std::uint64_t sourceTimestampNs{0};
    std::uint64_t sequence{0};
    std::string objectRef;

    nlohmann::json toJson() const;
    static SoftbusDataPoint fromJson(const nlohmann::json& j);
};

struct SoftbusAck {
    std::string requestId;
    std::string traceId;
    std::string deviceId;
    std::string pointId;
    bool success{false};
    std::string error;
    double executedValue{0.0};

    nlohmann::json toJson() const;
    static SoftbusAck fromJson(const nlohmann::json& j);
};

struct SoftbusEvent {
    std::string deviceId;
    std::string eventType;
    std::string message;
    std::uint64_t timestampNs{0};

    nlohmann::json toJson() const;
    static SoftbusEvent fromJson(const nlohmann::json& j);
};

std::string qualityToString(SoftbusQuality q);
SignalType signalTypeFromString(const std::string& s);
std::string signalTypeToString(SignalType t);
PointAccess accessFromString(const std::string& s);

} // namespace softbus::core
