"""CLI command: asa plan — dry-run showing what asa apply would do."""

import typer

from ..core import logging as log
from ..core.paths import find_project_root
from ..engine.applier.planner import generate_plan, print_plan
from ..engine.spec.parser import load_spec


def plan() -> None:
    """Show what 'asa apply' would do — dry-run, nothing is written.

    Reads .asa/spec.yaml and displays planned actions:
    CREATE, INSTALL, GENERATE, SKIP (already exists).
    """
    project_root = find_project_root()

    spec = load_spec(project_root)
    if spec is None:
        log.error(
            "No .asa/spec.yaml found. Run 'asa spec infer' or 'asa init' first."
        )
        raise typer.Exit(code=1)

    log.header("ASA Plan — based on .asa/spec.yaml")
    log.info(f"App: {spec.app.name} (mode: {spec.app.mode})")
    print()

    plan_data = generate_plan(project_root, spec)
    print_plan(plan_data)
