"""Tests for logging configuration."""

import logging

from azure_discovery.utils.logging import get_logger


def test_get_logger_quiet_sets_error_level_when_handlers_present() -> None:
    """When logger already has handlers and quiet=True, level is set to ERROR."""
    # First call attaches NullHandler so logger.handlers is truthy
    get_logger()
    # Second call with quiet=True hits the branch that sets ERROR and returns
    logger = get_logger(quiet=True)
    assert logger.level == logging.ERROR


def test_get_logger_sets_level_from_env_when_no_handlers() -> None:
    """When logger has no handlers, level is set from AZURE_DISCOVERY_LOG_LEVEL (or INFO)."""
    logger = logging.getLogger("azure_discovery")
    logger.handlers.clear()
    logger.setLevel(logging.NOTSET)
    # get_logger(quiet=False) with no handlers adds NullHandler and sets level from env
    out = get_logger(quiet=False)
    assert out.level != logging.NOTSET


def test_get_logger_quiet_sets_error_when_no_handlers() -> None:
    """When logger has no handlers and quiet=True, level is set to ERROR (covers line 62)."""
    logger = logging.getLogger("azure_discovery")
    logger.handlers.clear()
    out = get_logger(quiet=True)
    assert out.level == logging.ERROR
