/*
 * shins_util_f.h
 *
 *  Created on: Sep 15, 2021
 *      Author: shinsmgr
 */

#include <map>
#include <vector>
#include <string>
#include <iomanip>

#include <pthread.h>

#include "constants.h"

#include "logger.h"


#ifndef UTIL_SHINS_UTIL_F_H_
#define UTIL_SHINS_UTIL_F_H_

namespace shins
{
namespace util
{

enum EShinsMovements
{
    SHINS_MOV_NAMED = 0,
    SHINS_MOV_ABSOLUTE = 1,
    SHINS_MOV_RELATIVE = 2,

    SHINS_MOV_UNDEFINED = 31
};


enum EServiceStatus
{
    SERVICE_NOTCONNECTED,
    SERVICE_ALLOCATING,
    SERVICE_ALLOCATED,
    SERVICE_CONNECTED,
    SERVICE_TOBEINITED,
    SERVICE_ONLINE,
    SERVICE_ERROR
};


class Timer
{
    Nice::Time duration;
    Nice::Date creation;
public:
    Timer(Nice::Time durat)
    {
        creation = Nice::Date::now();
        duration = durat;
    }
    Nice::Time residual()
    {
        Nice::Time res = duration - (Nice::Date::now() - creation);
        if(res > Nice::Time())
            return res;
        else
            return Nice::Time();
    }
    bool elapsed()
    {
        return duration < (Nice::Date::now() - creation);
    }
    Nice::Time get_duration(){return duration;};
};


class shinslog
{
    shinslog(){};
    static int counter;
    static pthread_mutex_t m_mutex;
public:
    static char log[772];
    static char * init();
    static int call();
    static int back(int new_counter);
};

    unsigned char to_upper(unsigned char c);

    unsigned char to_lower(unsigned char c);

    std::string str_toupper(std::string s);

    std::string str_tolower(std::string s);

    std::string left(const std::string & s, int n);

    std::string right(const std::string & s, int n);

    bool contains(const std::string &s, const std::string & sub);

    const std::string & banner_string(const std::string & msg, char fill, int len, bool no_double_space = true);

    EShinsMovements detect_command_type(const std::string second, double & abs, double & rel, std::string & unit);

    std::string NamedStylePos(double val,const std::string & unit, EShinsMovements type);

    std::string remove_whitespaces(const std::string & original);

    const std::string & get_iso_time_str();
    const std::string & get_iso_gmtime_str();
    int SetTimeWorkingDirectory(const std::string & time_stamp);

    bool swab4(const void * source, void * dest, size_t size);

    bool get_bool_from_setup(const std::map<std::string, std::string> & map, const std::string & key, bool & val);

    std::map<std::string, std::string>
        extract_setup(const std::vector<std::string> & to_be_extracted, std::map<std::string, std::string> & TechCamSetup);
    void extract_setup(std::map<std::string, std::string> & to_be_extracted, const std::map<std::string, std::string> & InstSetup);

    char * get_char_star(const std::string & std_str);
    const std::string & getCurrentDataDirectory();

    void log_dictionary(std::string file, int line,const std::map<std::string, std::string> & dict);
    void SetDataSaveDirectory(const std::string & dir);

}// namespace util

}// namespace s



#endif /* UTIL_SHINS_UTIL_F_H_ */
