#ifndef HM_UTILS_H
#define HM_UTILS_H

#include <cstdio>
#include <string>
#include <vector>
#include <map>

#define LogM(l, x...) printf("[HmGate|%5s] %16s : ",logLevelName(l),__FUNCTION__),printf(x),printf("\n")
#define Log(l, x...) if (getLogStatus(l)) LogM(l, x)

namespace hm {
    enum Level {
        Closed, Trace, Info, Warn, Error
    };
    extern Level gConfLogLevel;
    extern std::string gConfFaceRemote, gConfCarRemote, gConfLoginUser, gConfLoginPass;
    extern unsigned int  gConfSearchGap, gConfSearchDuration, gConfServerPort;

    void ReadConfig(const char *path);

    const char *logLevelName(const Level &level);

    bool getLogStatus(const Level &level);

    bool startsWith(const std::string &str, const std::string &start);

    bool endsWith(const std::string &str, const std::string &end);

    std::string trim(const std::string &str);

    bool splitKeyValue(const std::string &src, std::string &key, std::string &value);

    std::vector<std::string> getIpList();

    int imageRead(const std::string &path, char *&buffer);

    int imgcpy(char *&dest, const std::string &src);

    void imageSave(const std::string &path, char *&start, const int &size);

    void imageSave(const std::string &path, unsigned char *&start, const unsigned int &size);

    time_t toTimestamp(
            const unsigned int &year, const unsigned int &mon, const unsigned int &day,
            const unsigned int &hour, const unsigned int &min, const unsigned int &sec
    );

    size_t onPostResponse(void *contents, size_t size, size_t nMem, std::string *output);

    void dataUpload(
            const std::string &url, const std::map<std::string, std::string> &data,
            unsigned char *&imgBuf, const unsigned int &bufSize
    );
}


#endif //HM_UTILS_H
