#include "Config.h"
#include <EEPROM.h>
#include <string.h>

Config::Config()
{
    EEPROM.begin(512);
}

Config::Config(int ID, char mqtt_broker[], int mqtt_port, char mqtt_username[], char mqtt_password[], char wlan_ssid[], char wlan_password[])
{
    Data.ID = ID;
    strcpy(Data.MQTT_Broker, mqtt_broker);
    Data.MQTT_Port = mqtt_port;
    strcpy(Data.MQTT_Username, mqtt_username);
    strcpy(Data.MQTT_Password, mqtt_password);
    strcpy(Data.WLAN_SSID, wlan_ssid);
    strcpy(Data.WLAN_Password, wlan_password);

    EEPROM.begin(512);
}

void Config::Load()
{
    EEPROM.get(0, this->Data);
}

void Config::Save()
{
    EEPROM.put(0, this->Data);
    EEPROM.commit();
}

bool Config::IsEmpty()
{
    return this->Data.ID == 0;
}