#pragma once

#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO

#include <DebugLog.h>
#include <Arduino.h>
#include <Network.h>
#include <NTPClient.h>
#include <ETH.h>
#include <SPI.h>

// PHY defines hardware related
#ifndef ETH_PHY_TYPE
#define ETH_PHY_TYPE ETH_PHY_W5500
#define ETH_PHY_ADDR 1
#define ETH_PHY_CS 16
#define ETH_PHY_IRQ 12
#define ETH_PHY_RST 39
#endif

// SPI pins
#define ETH_SPI_SCK 15
#define ETH_SPI_MISO 14
#define ETH_SPI_MOSI 13

namespace drivers
{

    class Ethernet : public ETHClass
    {

    public:
        Ethernet(const std::string hostname);
        ~Ethernet();

        void onEvent(arduino_event_id_t event, arduino_event_info_t info);
        const bool isConnected();
        const bool getNtpTime(time_t &time);

    private:
        const std::string m_hostname;
        bool m_connected;
        NetworkUDP m_udp;
        IPAddress m_localIP;
        NTPClient m_timeClient;
    };

}
