"""Parsers package for backward compatibility with legacy code.

This module provides backward compatibility with the legacy parser system.
It imports parsers from the new modular structure and exposes them through
the legacy interface.
"""

import importlib
import logging
from typing import List, Type

from domd.core.parsing.base import BaseParser

logger = logging.getLogger(__name__)

# List of parser modules to import
PARSER_MODULES = [
    "domd.parsers.build_systems",
    "domd.parsers.ci_cd",
    "domd.parsers.docker",
    "domd.parsers.javascript",  # This now includes package.json parser
    "domd.parsers.python",
]


def get_all_parsers() -> List[Type[BaseParser]]:
    """Get all available parsers from the legacy parser modules.

    This function is used as a fallback when the new parser registry
    doesn't contain any parsers.

    Returns:
        List of parser classes
    """
    parsers = []

    for module_name in PARSER_MODULES:
        try:
            module = importlib.import_module(module_name)

            # Look for a get_parsers function in the module
            if hasattr(module, "get_parsers"):
                module_parsers = module.get_parsers()
                parsers.extend(module_parsers)
            else:
                logger.debug(f"Module {module_name} has no get_parsers function")

        except ImportError as e:
            logger.debug(f"Failed to import parser module {module_name}: {e}")

    logger.debug(f"Loaded {len(parsers)} legacy parsers")
    return parsers
