"""
logger.py — Project-wide configured logging instance.

Imports the `Logs` backend class from log_backend.py (formerly Logger.py;
renamed to avoid a case-only filename collision with this module, which
breaks any case-insensitive filesystem — macOS default HFS+/APFS, Windows).
"""
import os
from Core.env_loader import PROJECT_ROOT
from Core.log_backend import Logs

# Single shared instance — all modules use this
_logs = Logs(main_log_file=os.path.join(PROJECT_ROOT, "logs", "main.log"))

# Pre-configured module loggers
_engines = {}


def get_logger(module_name: str) -> Logs:
    """
    Get a logger configured for a specific module.
    Logs go to logs/{module_name}.log

    Usage:
        from Core.logger import get_logger
        log = get_logger("brain")
        log.LogsMessages("Marcus started", "info")
    """
    if module_name not in _engines:
        _logs.LogEngine(
            os.path.join(PROJECT_ROOT, "logs"),
            f"{module_name}.log"
        )
        _engines[module_name] = _logs
    return _logs


def log(message: str, level: str = "info", module: str = "main"):
    """Quick log function — no setup needed."""
    _logs.LogsMessages(
        message,
        message_type=level,
        folder_name=os.path.join(PROJECT_ROOT, "logs"),
        file_name=f"{module}.log"
    )


def log_and_print(message: str, level: str = "info", module: str = "main"):
    """Log to file AND print to console."""
    _logs.print_and_log(
        message,
        message_type=level,
        folder_name=os.path.join(PROJECT_ROOT, "logs"),
        file_name=f"{module}.log"
    )
