#pragma once

#include <QDateTime>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>

namespace softbus::devices
{




// 具体设备种类（用于选择 driver / 解析 endpoint）
enum class DeviceKind {
    Unknown,
    Serial,
    Can,
    Tcp,
    Udp,
    Network,      // 泛指 network（无法区分 tcp/udp 时）
    Virtual,
    Distributed,
};

struct DeviceInfo
{
    int         id{0};
    QString     endpoint;
    QString     name;
    QString     type;            // "serial" / "can" / "network" / ...
    DeviceKind  kind{DeviceKind::Unknown};
    int         address{0};
    QString     protocol;
    QString     protocolDetail;
    QJsonObject properties;
    QString     status{QStringLiteral("online")};
    bool        isActive{true};
    QDateTime   lastSeen;

    QString toJson() const
    {
        QJsonObject obj;
        obj[QStringLiteral("id")] = id;
        obj[QStringLiteral("endpoint")] = endpoint;
        obj[QStringLiteral("name")] = name;
        obj[QStringLiteral("type")] = type;
        obj[QStringLiteral("kind")] = static_cast<int>(kind);
        obj[QStringLiteral("address")] = address;
        obj[QStringLiteral("protocol")] = protocol;
        obj[QStringLiteral("protocol_detail")] = protocolDetail;
        obj[QStringLiteral("properties")] = properties;
        obj[QStringLiteral("status")] = status;
        obj[QStringLiteral("isActive")] = isActive;
        if (lastSeen.isValid()) {
            obj[QStringLiteral("lastSeen")] = lastSeen.toString(Qt::ISODate);
        }
        const QJsonDocument doc(obj);
        return QString::fromUtf8(doc.toJson(QJsonDocument::Compact));
    }
};

struct BusMessage
{
    QString id;
    QString source;
    QString destination;
    QJsonObject payload;
    qint64 timestamp{0};
};

// 纯 helper：不做 IO，仅做字符串/endpoint 到 DeviceKind/driverKey 的映射
DeviceKind kindFromType(const QString& typeStr);
DeviceKind inferDeviceKindFromEndpoint(const QString& endpoint);
QString    driverKeyFor(DeviceKind kind);

} // namespace softbus::devices

