"""Debug logging gated by add-on setting."""
from __future__ import annotations

import xbmc

from xbmcaddon import Addon

from .constants import ADDON_ID

_addon: Addon | None = None


def _get_addon() -> Addon:
    global _addon
    if _addon is None:
        _addon = Addon(ADDON_ID)
    return _addon


def debug(message: str) -> None:
    if _get_addon().getSettingBool("debug_logging"):
        xbmc.log(f"[{ADDON_ID}] {message}", xbmc.LOGDEBUG)


def info(message: str) -> None:
    xbmc.log(f"[{ADDON_ID}] {message}", xbmc.LOGINFO)


def error(message: str) -> None:
    xbmc.log(f"[{ADDON_ID}] {message}", xbmc.LOGERROR)
