#ifndef SH_PLATFORM_ESP8266_H
#define SH_PLATFORM_ESP8266_H

#include <Arduino.h>

// --- WiFi / HTTP / WebServer (ESP8266 specific) ---
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>

// --- Storage / OTA ---
#include <EEPROM.h>
#include <Updater.h>

// -------------------- Common aliases --------------------
using sh_web_server_t = ESP8266WebServer;

// -------------------- Platform helpers --------------------
static inline String platform_get_unique_id() {
  return String(ESP.getChipId(), HEX);
}

static inline String platform_get_mac_string() {
  uint8_t mac[6];
  WiFi.macAddress(mac);

  char buf[13];
  sprintf(buf, "%02X%02X%02X%02X%02X%02X",
          mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

  return String(buf);
}

// WiFi radio tuning (ESP8266-only API)
static inline void platform_wifi_apply_radio_tuning() {
  WiFi.setPhyMode(WIFI_PHY_MODE_11G);
  WiFi.setSleepMode(WIFI_NONE_SLEEP);

  // TX power: 0..20.5 dBm
  WiFi.setOutputPower(20.0f);
}

// WiFi scan: is network secured?
static inline bool platform_wifi_is_secured(int net_idx) {
  return (WiFi.encryptionType(net_idx) != ENC_TYPE_NONE);
}

// OTA: calculate sketch space (matches your existing logic)
static inline size_t platform_ota_get_sketch_space() {
  return (ESP.getFreeSketchSpace() - 0x2000) & 0xFFFFF000;
}

#endif // SH_PLATFORM_ESP8266_H
