/**
 * @file Config.h
 * @author apio (cloudapio.eu)
 * @brief Configuration file parsing.
 *
 * @copyright Copyright (c) 2024, the Luna authors.
 *
 */

#pragma once
#include <luna/HashMap.h>
#include <luna/RefString.h>
#include <os/File.h>
#include <os/Path.h>

namespace os
{
    class ConfigFile
    {
      public:
        static Result<OwnedPtr<ConfigFile>> open(os::Path path);

        Option<StringView> read_string(StringView key);
        StringView read_string_or(StringView key, StringView default_value);

        Option<i64> read_number(StringView key);
        i64 read_number_or(StringView key, i64 default_value);

        Option<bool> read_boolean(StringView key);
        bool read_boolean_or(StringView key, bool default_value);

        Result<void> write_string(StringView key, StringView value);
        Result<void> write_number(StringView key, int value);
        Result<void> write_boolean(StringView key, bool value);

        Result<void> sync();

      private:
        os::Path m_path { "" };

        HashMap<RefString, RefString> m_data;
    };
}