#ifndef LEVELDB_RS_BINDING_LOGGER_H
#define LEVELDB_RS_BINDING_LOGGER_H

#include <leveldb/c.h>
#include <leveldb/env.h>

#ifdef __cplusplus
extern "C" {
#endif

// Define leveldb_logger_t to match LevelDB's internal structure from "deps/leveldb/db/c.cc"
struct leveldb_logger_t {
  void* rep;
};

// "log line" related functions implemented in Rust (logger.rs)
typedef struct leveldb_rs_log_line_t
    leveldb_rs_log_line_t; /* Forward declaration for opaque leveldb_rs_log_line_t struct from Rust */
leveldb_rs_log_line_t* leveldb_rs_logline_create(void* rust_logger);
void leveldb_rs_logline_destroy(leveldb_rs_log_line_t* logline);
void leveldb_rs_logline_process(leveldb_rs_log_line_t* logline, const char* thread_id, const char* message);

// Logger functions implemented in C++ (logger.cpp)
leveldb_logger_t* leveldb_rs_logger_create(void* rust_logger);
void leveldb_rs_logger_destroy(leveldb_logger_t* logger);

#ifdef __cplusplus
}

namespace leveldb_rs {
constexpr const int kMaxThreadIdSize = 32;
constexpr const int kStackBufferSize = 512;

class RsLogger final : public leveldb::Logger {
  public:
  explicit RsLogger(void* rust_logger) noexcept;
  ~RsLogger() override = default;

  // Implementation of Logv method from leveldb::Logger
  // Main logic is from internal logger, except those parts
  // interact with C callbacks (implemented in Rust layer)
  void Logv(const char* format, std::va_list arguments) override;

  private:
  void* rust_logger_; // Opaque pointer to Rust Logger
};
} // namespace leveldb_rs

#endif

#endif // LEVELDB_RS_BINDING_LOGGER_H
