#ifndef CORE_LOGGER_H
#define CORE_LOGGER_H

#include <cstdint>
#include <fstream>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <utility>

#include "core/error.h"
#include "core/types.h"

namespace dofs {

class Logger final {
public:
        Logger(std::string_view path, bool append) noexcept;
        ~Logger() noexcept;

        Logger(const Logger &) = delete;
        Logger &operator=(const Logger &) = delete;
        Logger(Logger &&) = delete;
        Logger &operator=(Logger &&) = delete;

        bool is_open() const noexcept {
                return _is_open;
        }

        void write_line(std::string_view line) noexcept;

        void flush() noexcept;
        void close() noexcept;

        std::string_view path() const noexcept {
                return _path;
        }

private:
        bool open(std::ios::openmode mode) noexcept;

        std::string _path;
        std::ofstream _stream;
        bool _is_open{false};
        std::mutex _mutex;
};

} // namespace dofs

#endif // CORE_LOGGER_H
