#ifndef MESH_PUBLISH_H
#define MESH_PUBLISH_H

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

// Initialize SX1262 radio via RadioLib. Returns true on success.
bool mesh_init(SPIClass& spi);

// Serialize a DetectionEvent into the wire format and transmit via LoRa.
bool mesh_publish_detection(const DetectionEvent& evt);

// Publish a raw packet (used by FFPS for candidate/corroborate messages).
bool mesh_publish_raw(const uint8_t* data, size_t len);

// Receive a packet (non-blocking). Returns number of bytes received, 0 if none.
// Fills buffer up to max_len, sets rssi and snr.
int mesh_receive(uint8_t* buffer, size_t max_len, float& rssi, float& snr);

// Put radio into receive mode (call once after init, re-call after each TX).
void mesh_start_receive();

// Serialize DetectionEvent to byte buffer. Returns number of bytes written.
size_t mesh_serialize_event(const DetectionEvent& evt, uint8_t* buf, size_t buf_len);

// Deserialize byte buffer to DetectionEvent. Returns true on success.
bool mesh_deserialize_event(const uint8_t* buf, size_t len, DetectionEvent& evt);

// Get reference to the radio module (for advanced use)
SX1262& mesh_get_radio();

#endif // MESH_PUBLISH_H
