"""
Logging Configuration

Provides consistent logging setup for CLI tools and modules.
"""

import logging
import sys
from typing import Optional


def setup_cli_logging(
    level: int = logging.INFO,
    name: Optional[str] = None,
    format_string: Optional[str] = None,
) -> logging.Logger:
    """
    Configure logging for CLI applications.

    Args:
        level: Logging level (default: INFO)
        name: Logger name (default: root logger)
        format_string: Custom format string (default: simple CLI format)

    Returns:
        Configured logger instance
    """
    if format_string is None:
        format_string = "%(message)s"

    # Configure root logger or specific logger
    logger = logging.getLogger(name)
    logger.setLevel(level)

    # Remove existing handlers to avoid duplicates
    logger.handlers.clear()

    # Create console handler
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(level)
    handler.setFormatter(logging.Formatter(format_string))
    logger.addHandler(handler)

    return logger


def setup_verbose_logging(
    level: int = logging.DEBUG,
    name: Optional[str] = None,
) -> logging.Logger:
    """
    Configure verbose logging with timestamps and module info.

    Args:
        level: Logging level (default: DEBUG)
        name: Logger name (default: root logger)

    Returns:
        Configured logger instance
    """
    format_string = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
    return setup_cli_logging(level=level, name=name, format_string=format_string)
