#include "load.h"

namespace Lib_Load{
    void Load::set_count_error(int count_error) {
        process.set_count_error(count_error);
    }
    string Load::get_cmd_error() {
        return process.get_cmd_error();
    }
    map<string, string>& Load::get_load_data(std::map <string, string> &map_temp, string cmd) {
        string response = "";
        string key = "";
        string value = "";
        response = process.call_all_sections(cmd);
        vector<string> vec_str_key_value = Utils::split(response, '\n');
        for (const string &param: vec_str_key_value) {
            if ((param.find("(null)") == std::string::npos) && (param.length() != 0 )) { 
                if (param.find("=") != std::string::npos) {
                    size_t index = param.find("=");
                    key = param.substr(0, index);
                    value = param.substr(index + 1, param.length());
                    Utils::str_replace_all(value, " \"","");
                    Utils::str_replace_all(value, "\"","");
                    map_temp[key] = value;
                }
            }
        }
        return map_temp;
    }
    int Load::get_count_error() {
        return process.get_count_error();
    }
    
}