#pragma once

#include <Arduino.h>
#include "config.h"

#ifndef ENABLE_HIL_TRACE
#define ENABLE_HIL_TRACE 0
#endif
enum class HilFault : uint8_t {
  DropChunk = 0,
  DuplicateChunk,
  CorruptChunk,
  SuppressAck,
  DelayAck,
  WrongAckBatch,
  Count
};

#if ENABLE_HIL_TRACE

void hil_trace_init(DeviceRole role, uint16_t short_id, int reset_reason);
void hil_trace_event(const char *event, const char *fields_json = nullptr);
void hil_trace_eventf(const char *event, const char *fields_fmt, ...);
void hil_trace_poll_commands();
bool hil_fault_take(HilFault fault);
uint32_t hil_fault_delay_ms();
uint32_t hil_crc32(const uint8_t *data, size_t len);
void hil_trace_health(uint8_t queue_depth, uint8_t build_depth, uint8_t retry_count);

#else

inline void hil_trace_init(DeviceRole, uint16_t, int) {}
inline void hil_trace_event(const char *, const char * = nullptr) {}
inline void hil_trace_eventf(const char *, const char *, ...) {}
inline void hil_trace_poll_commands() {}
inline bool hil_fault_take(HilFault) { return false; }
inline uint32_t hil_fault_delay_ms() { return 0; }
inline uint32_t hil_crc32(const uint8_t *, size_t) { return 0; }
inline void hil_trace_health(uint8_t, uint8_t, uint8_t) {}

#endif
