"""asa install — Install ASA foundation module."""

import typer

from ..core import logging as log
from ..core.errors import AsaError
from ..core.paths import find_project_root


def run_install(module_name: str) -> None:
    """Install an ASA foundation module."""
    from ..engine_loader import require_engine
    require_engine()
    from ..engine.installer.installer import install_module
    try:
        project_root = find_project_root()
        created = install_module(module_name, project_root)
        log.success(f"Module installed: {module_name}")
        for path in created:
            log.detail(f"Created: {path}")

    except AsaError as e:
        log.error(str(e))
        raise typer.Exit(1)
    except Exception as e:
        log.error(f"[INTERNAL ERROR] {e}")
        raise typer.Exit(2)
