#include "data_model.h"
#include <esp_mac.h>

void init_device_ids(uint16_t &short_id, char *device_id, size_t device_id_len) {
  uint8_t mac[6] = {0};
  // Read base MAC without needing WiFi to be started.
  esp_read_mac(mac, ESP_MAC_WIFI_STA);
  short_id = (static_cast<uint16_t>(mac[4]) << 8) | mac[5];
  snprintf(device_id, device_id_len, "dd3-%04X", short_id);
}

const char *rx_reject_reason_text(RxRejectReason reason) {
  switch (reason) {
    case RxRejectReason::CrcFail:
      return "crc_fail";
    case RxRejectReason::BadProtocol:
      return "bad_protocol_version";
    case RxRejectReason::WrongRole:
      return "wrong_role";
    case RxRejectReason::WrongPayloadType:
      return "wrong_payload_type";
    case RxRejectReason::LengthMismatch:
      return "length_mismatch";
    case RxRejectReason::DeviceIdMismatch:
      return "device_id_mismatch";
    case RxRejectReason::BatchIdMismatch:
      return "batch_id_mismatch";
    default:
      return "none";
  }
}
