#pragma once

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

constexpr size_t LORA_MAX_PAYLOAD = 230;

struct LoraPacket {
  uint8_t protocol_version;
  DeviceRole role;
  uint16_t device_id_short;
  PayloadType payload_type;
  uint8_t payload[LORA_MAX_PAYLOAD];
  size_t payload_len;
  int16_t rssi_dbm;
  float snr_db;
};

void lora_init();
bool lora_send(const LoraPacket &pkt);
bool lora_receive(LoraPacket &pkt, uint32_t timeout_ms);
RxRejectReason lora_get_last_rx_reject_reason();
void lora_idle();
void lora_sleep();
void lora_receive_continuous();
bool lora_receive_window(LoraPacket &pkt, uint32_t timeout_ms);
uint32_t lora_airtime_ms(size_t packet_len);
