#include "hardware.h"
#include <esp_system.h>

SystemDiagnostics sysInfo;

void SystemDiagnostics::update() {
  freeHeap = ESP.getFreeHeap();
  minFreeHeap = ESP.getMinFreeHeap();
  uptime = millis() / 1000;
  cpuFreq = ESP.getCpuFreqMHz();
  temperature = temperatureRead();

  wifiRSSI = 0; // Filled by network module
  resetReason = esp_reset_reason();
}

void SystemDiagnostics::print() {
  Serial.println("\n=== System Diagnostics ===");
  Serial.printf("Uptime: %lu s\n", uptime);
  Serial.printf("Free Heap: %lu bytes\n", freeHeap);
  Serial.printf("Min Free Heap: %lu bytes\n", minFreeHeap);
  Serial.printf("CPU Freq: %.0f MHz\n", cpuFreq);
  Serial.printf("Core Temp: %.1f C\n", temperature);
  Serial.printf("Reset Reason: %d\n", resetReason);
  Serial.println("==========================\n");
}
