#include "lumacs/logger.hpp"
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <vector>

namespace lumacs {

void Logger::init() {
    // Check if already initialized
    if (spdlog::get("lumacs")) {
        return;
    }

    // Create console sink
    auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
    console_sink->set_level(spdlog::level::debug);
    console_sink->set_pattern("[%H:%M:%S.%e] [%^%l%$] %v");

    // Create file sink
    auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("lumacs_debug.log", true);
    file_sink->set_level(spdlog::level::trace);

    // Combine sinks
    std::vector<spdlog::sink_ptr> sinks {console_sink, file_sink};
    auto logger = std::make_shared<spdlog::logger>("lumacs", sinks.begin(), sinks.end());
    
    logger->set_level(spdlog::level::debug);
    logger->flush_on(spdlog::level::debug);

    spdlog::register_logger(logger);
    spdlog::set_default_logger(logger);
}

std::shared_ptr<spdlog::logger> Logger::get() {
    return spdlog::get("lumacs");
}

} // namespace lumacs
