#include "wrapper_load_save.h"



Wrapper_load_save::Wrapper_load_save(/* args */) {
    //obj_quotas_sys.set_map_gui(map_gui_cfg);
    //obj_quotas_ubconfig.set_map_gui(map_gui_cfg);
}

Wrapper_load_save::~Wrapper_load_save()
{
}

void Wrapper_load_save::set_map_gui(map_str_str* map_gui_cfg) {
    this->map_gui_cfg = map_gui_cfg;
}

void Wrapper_load_save::set_map_global(map_str_str* map_global_cfg) {
    this->map_global_cfg = map_global_cfg;
}

void Wrapper_load_save::set_map_local(map_str_str* map_system_cfg) {
    this->map_system_cfg = map_system_cfg;
}

void Wrapper_load_save::set_vec_key(vector<string> vec_param_names) {
    this->vec_param_names = vec_param_names;
}

int Wrapper_load_save::load_global_cfg() {
    this->load_template(map_global_cfg, global_load);
    *map_gui_cfg = *map_global_cfg;
    return 1;
    
}

int Wrapper_load_save::load_system_cfg() {
    this->load_template(map_system_cfg, system_load);
    *map_gui_cfg = *map_system_cfg;
    return 0;
    
}

void Wrapper_load_save::load_template(map_str_str* map_temp, string cmd) {
    if (cmd.find("system") != string::npos) {
        this->init_dict("system");
    }
    else {
        this->init_dict("global");
    }
    *map_temp = obj_load.get_load_data(*map_temp, cmd);
}

int Wrapper_load_save::wrapper_save_global_cfg() {
    this->set_data_cfg();
    if (this->save_template("boot", "global")) {
        *map_global_cfg = *map_gui_cfg;
        return 5;
    }
    else {
        *map_global_cfg = *map_gui_cfg;
        return 3;
    }
}

int Wrapper_load_save::wrapper_save_system_cfg() {
    this->set_data_cfg();
    if (this->save_template("boot", "system")) {
        *map_system_cfg = *map_gui_cfg;
        return 5;
    }
    else {
        *map_system_cfg = *map_gui_cfg;
        return 2;
    }
    
}


int Wrapper_load_save::wrapper_save_all_cfg() {
    this->set_data_cfg();
    bool _flag_save_global = this->save_template("boot", "global");;
    bool _flag_save_local = this->save_template("boot", "system");
    if (_flag_save_global && _flag_save_local) {
        *map_global_cfg = *map_gui_cfg;
        *map_system_cfg = *map_gui_cfg;
        return 5;
    }
    else {
        *map_global_cfg = *map_gui_cfg;
        *map_system_cfg = *map_gui_cfg;
        return 4;
    }
    
    
}

int Wrapper_load_save::get_error_load() {
    return obj_load.get_count_error();
}
int Wrapper_load_save::get_error_save() {
    return obj_save.get_count_error();
}

bool Wrapper_load_save::save_template(string section, string flag_save) {
    bool flag_no_save = true;
    obj_save.set_data_local(*map_system_cfg);
    obj_save.set_data_global(*map_global_cfg);
    obj_save.set_data_gui(*map_gui_cfg);
    obj_save.set_vec_params(vec_param_names);
    obj_save.save(section, flag_save);
    vector<string> obj_vec_error = obj_save.get_error();
    flag_no_save = obj_save.get_state_save();
    return flag_no_save;
}

void Wrapper_load_save::init_dict(string flag_load) {
    map_str_str map_gui_cfg_n;
    map_gui_cfg_n[""] = "";

    *map_gui_cfg = map_gui_cfg_n;
    if (flag_load == "global") {
        *map_global_cfg = *map_gui_cfg;
    }
    else if (flag_load == "system") {
        *map_system_cfg = *map_gui_cfg;
    }
}

void Wrapper_load_save::set_data_cfg() {
    // TODO:
    // Написать функцию
}