// src/macros.rs

// Non-fallible macro helper
#[doc(hidden)]
#[macro_export]
macro_rules! __log_easy_nonfallible {
    ($method:ident, $($arg:tt)*) => {{
        if let Some(logger) = $crate::global_logger() {
            logger.$method(&format!($($arg)*));
        } else {
            eprintln!("log-easy: global logger not initialized (call log_easy::init or init_with)");
        }
    }};
}

// Fallible macro helper
#[doc(hidden)]
#[macro_export]
macro_rules! __log_easy_fallible {
    ($method:ident, $($arg:tt)*) => {{
        match $crate::global_logger() {
            Some(logger) => logger.$method(&format!($($arg)*)),
            None => Err(std::io::Error::new(
                std::io::ErrorKind::NotFound,
                "log-easy: global logger not initialized (call log_easy::init or init_with)",
            )),
        }
    }};
}

#[macro_export]
macro_rules! trace { ($($arg:tt)*) => { $crate::__log_easy_nonfallible!(trace, $($arg)*) }; }
#[macro_export]
macro_rules! debug { ($($arg:tt)*) => { $crate::__log_easy_nonfallible!(debug, $($arg)*) }; }
#[macro_export]
macro_rules! info  { ($($arg:tt)*) => { $crate::__log_easy_nonfallible!(info,  $($arg)*) }; }
#[macro_export]
macro_rules! warn  { ($($arg:tt)*) => { $crate::__log_easy_nonfallible!(warn,  $($arg)*) }; }
#[macro_export]
macro_rules! error { ($($arg:tt)*) => { $crate::__log_easy_nonfallible!(error, $($arg)*) }; }

#[macro_export]
macro_rules! try_trace { ($($arg:tt)*) => { $crate::__log_easy_fallible!(try_trace, $($arg)*) }; }
#[macro_export]
macro_rules! try_debug { ($($arg:tt)*) => { $crate::__log_easy_fallible!(try_debug, $($arg)*) }; }
#[macro_export]
macro_rules! try_info  { ($($arg:tt)*) => { $crate::__log_easy_fallible!(try_info,  $($arg)*) }; }
#[macro_export]
macro_rules! try_warn  { ($($arg:tt)*) => { $crate::__log_easy_fallible!(try_warn,  $($arg)*) }; }
#[macro_export]
macro_rules! try_error { ($($arg:tt)*) => { $crate::__log_easy_fallible!(try_error, $($arg)*) }; }
