#ifndef SETTINGS_HPP_
#define SETTINGS_HPP_

#include <string>
#include <optional>
#include <unordered_map>
#include <iostream>
#include <Utilities/TemperatureScale.hpp>
#include <KeyActionMap/KeyActionMap.hpp>

/**
 * @brief A class which stores settings.
 * 
 * Use the global variable `settings` for the singleton instance.
 */
class Settings
{
private:
    std::string sessionTypeName;
    std::unordered_map<std::string, std::string> unknownSettings;

    void printComments(std::ofstream &os, const char *shortDesc, const char *longDesc);

public:
    Settings();

    /**
     * @brief Set a named key to a value.
     * 
     * @param key The setting key. These match the name of the property in this class.
     * @param value The value to use for this setting.
     * @param preserveUnknown If true, and the key is not recognised, it'll be preserved.
     * @return Empty string if successful; an error message otherwise.
     */
    std::string set(std::string key, std::string value, bool preserveUnknown = false);

    /**
     * @brief Load the settings from the appropriate file, then save again.
     */
    void init();

    /**
     * @brief Save the settings to the appropriate file.
     */
    void save();

    #define DECL_COMMON_SETTING(type, name, ...) type name;
    #include <Settings/SettingsList.hpp>
};

/**
 * @brief The singleton settings instance.
 */
extern Settings settings;

#endif
