#ifndef HOMEKIT_LIB_MQTT_MODULE_DIAGNOSTICS_H
#define HOMEKIT_LIB_MQTT_MODULE_DIAGNOSTICS_H

#include <stdint.h>
#include <homekit/mqtt/module.h>

namespace homekit::mqtt {

struct DiagnosticsFlags {
    uint8_t state: 1;
    uint8_t config_changed_value_present: 1;
    uint8_t config_changed: 1;
    uint8_t reserved: 5;
} __attribute__((packed));

struct MqttInitialDiagnosticsPayload {
    uint32_t ip;
    uint8_t fw_version;
    int8_t rssi;
    uint32_t free_heap;
    DiagnosticsFlags flags;
} __attribute__((packed));

struct MqttDiagnosticsPayload {
    int8_t rssi;
    uint32_t free_heap;
    DiagnosticsFlags flags;
} __attribute__((packed));


class MqttDiagnosticsModule: public MqttModule {
private:
    bool initialSent;

public:
    MqttDiagnosticsModule()
        : MqttModule(30)
        , initialSent(false) {}

    void init(Mqtt& mqtt) override;
    void tick(Mqtt& mqtt) override;
};

}

#endif //HOMEKIT_LIB_MQTT_MODULE_DIAGNOSTICS_H
