// #include <WiFi.h>
// #include <WiFiUdp.h>
// #include <NTPClient.h>
// #include <ESP32Time.h>
#include "Zone.h"
#include "ZoneProgram.h"
#include "ControlUnit.h"

// const char* ntpServer = "europe.pool.ntp.org";  //Modify as per your country
// const long  gmtOffset_sec = 7200; // Offset from UTC (in seconds) (Italia GMT 2:00 // 2*60*60 = 19800) Modify as per your country
// const int   daylightOffset_sec = 3600; // Daylight offset (in seconds)

// bool autoUpdate = true;

// WiFiUDP ntpUDP;
// NTPClient timeClient(ntpUDP, ntpServer);
// ESP32Time rtc(gmtOffset_sec);

struct tm t = {0, 0, 0, 0, 0, 0, 0, 0, 0};
ControlUnit controlUnit;
Zone zone1(1, "Casetta");
Zone zone2(2, "Sgocciolatoio");

void setup() {
  Serial.begin(9600);
  // controlUnit.addZone(1, "Casetta");
  // controlUnit.addZone(2, "Sgocciolatoio");
  controlUnit.addZone(zone1);
  controlUnit.addZone(Zone(2, "Sgocciolatoio"));
  Serial.println(controlUnit.getZoneCount());
  Serial.println(zone1.getName());
  Zone* zonePtr = &zone1;
  Serial.println(zonePtr->getName()); 
  Serial.println(controlUnit.getZone(1)->getName());
  // Serial.print("Connecting to WiFi");
  // WiFi.begin("Wokwi-GUEST", "", 6);
  // while (WiFi.status() != WL_CONNECTED) {
  //   delay(100);
  //   Serial.print(".");
  // }
  // Serial.println(" Connected!");

  // if(autoUpdate) {
  //   timeClient.begin();
  //   timeClient.update();
  //   Serial.println(timeClient.getFormattedTime());
  //   rtc.setTime(timeClient.getEpochTime());
  // }
}

void loop() {
  if (!Serial.available()) {
    return;
  }

  String command = Serial.readString();
  command.trim();

  if (command == "zona 1") {
    Serial.println(zone1.getName());
  } else if (command == "zona 2") {
    Serial.println(controlUnit.getZone(1)->getName());
  } else if (command == "zone") {
    Serial.println(controlUnit.getZoneCount());
  }

  // Serial.println(timeClient.getFormattedTime());
  // Serial.println(autoUpdate);
  // Serial.println(rtc.getTimeDate());
  // delay(1000);
  // if(autoUpdate) {
  //   autoUpdate = false;
  // }

}