#ifndef TILE_BASE_CONFIG_INI_FILE_CONFIG_H
#define TILE_BASE_CONFIG_INI_FILE_CONFIG_H

#pragma once

#include "tile/base/config/configuration.h"
#include <map>

namespace tile {
class IniFileConfiguration : public Configuration {
public:
    using Ptr = RefPtr<IniFileConfiguration>;

    IniFileConfiguration();
    ~IniFileConfiguration() override;
    // IniFileConfig(std::istream &istr);
    // IniFileConfig(const std::string &path);
    bool load(std::istream &istr);
    bool load(const std::string &path);

protected:
    bool GetRaw(const Slice &key, std::string *value) const override;
    bool SetRaw(const Slice &key, const Slice &value) override;
    void RemoveRaw(const Slice &key) override;
    Keys Enumerate(const Slice &range) const override;

private:
    void ParseLine(std::istream &istr);

    struct ICompare {
        bool operator()(const std::string &s1, const std::string &s2) const;
    };

    typedef std::map<std::string, std::string, ICompare> IStringMap;
    IStringMap map_;
    std::string section_key_;
};
}// namespace tile

#endif// TILE_BASE_CONFIG_INI_FILE_CONFIG_H
