#ifndef GERMANAIRLINESVA_GACONNECTOR_CONFIG_H
#define GERMANAIRLINESVA_GACONNECTOR_CONFIG_H

#include <map>

#include <fstream>
#include <map>
#include <string>
#include <vector>

#include "util.hpp"

namespace germanairlinesva_config
{
  static inline std::map<std::string, std::string>
      readConfig(const std::string &file)
  {
    std::ifstream config(file);
    std::map<std::string, std::string> settings;

    std::string line;
    while (std::getline(config, line)) {
      std::vector<std::string> fields = germanairlinesva_util::split(line, '=');
      if (fields.size() >= 2) {
        germanairlinesva_util::trim(fields[0]);
        germanairlinesva_util::trim(fields[1]);
        settings[fields[0]] = fields[1];
      }
    }

    config.close();
    return settings;
  }

  static inline void
      writeConfig(const std::map<std::string, std::string> &config,
                  const std::string &file)
  {
    std::ofstream cfg(file);
    for (const std::pair<const std::string, std::string> &entry : config) {
      cfg << entry.first << '=' << entry.second << '\n';
    }
    cfg.close();
  }
} // namespace germanairlinesva_config
#endif
