
using namespace std;

bool isStringNumbers(const std::string &str)
{
    return str.find_first_not_of("0123456789") == std::string::npos;
}

class systemSettings
{
    public:
        systemSettings();
        void restart();  // restart controller
        void logActivity(short source, short typeID, short pinID, short action, std::string note);  // log controller activity
        std::string format_number(int num, int l);
    private:
        unsigned long long currentMillisLastSync = 0;
        unsigned long long prevTimeSyncMillis = 0;
};
systemSettings::systemSettings(){}


std::vector<int> getIndexes(std::vector<std::string> &input, std::string searched) {
    std::vector<int> result;

    for (int i = 0; i < input.size(); i++) {
        if (input[i] == searched) {
            result.push_back(i);
        }
    }

    return result;
}

std::string systemSettings::format_number(int num, int l) {  // used to add zeros in front of number
    ostringstream out;
    out << std::internal << std::setfill('0') << std::setw(l) << num;
    return out.str();
}

void systemSettings::logActivity(short source, short typeID, short pinID, short action, std::string note)  // log controller activity
{
    // std::cout << "logActivity -------- " << "" << std::endl;
    // std::cout << "source =     " << source << std::endl;
    // std::cout << "typeID =     " << typeID << std::endl;
    // std::cout << "pinID =      " << pinID << std::endl;
    // std::cout << "action =     " << action << std::endl;
    // std::cout << "note =       " << note << std::endl;

    connectMysql();
    std::string query = "INSERT INTO log(logSourceID, logTypeID, logPinID, logActionID, logTime, note) VALUES (" + to_string(source) + "," + to_string(typeID) + "," + to_string(pinID) + "," + to_string(action) + "," + to_string(currentMillisTime / 1000) + ",'" + note + "')";
    mysql_query(conn, query.c_str());  // run query
    mysql_disconnect(); 
    // delay(100);
}

void systemSettings::restart()  // restart controller
{
    std::string comm = "sudo reboot";
    system(comm.c_str());
}

systemSettings systemSettings;