"""
emergency.launch.py — Launch the emergency behavior system (Issue #169).

Usage
-----
  ros2 launch saltybot_emergency emergency.launch.py
  ros2 launch saltybot_emergency emergency.launch.py \
      stop_distance_m:=0.30 max_retries:=3
"""

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node


def generate_launch_description():
    pkg_share = get_package_share_directory("saltybot_emergency")
    default_params = os.path.join(pkg_share, "config", "emergency_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument(
            "params_file",
            default_value=default_params,
            description="Path to emergency_params.yaml",
        ),
        DeclareLaunchArgument(
            "stop_distance_m",
            default_value="0.30",
            description="Obstacle distance triggering MAJOR stop (m)",
        ),
        DeclareLaunchArgument(
            "max_retries",
            default_value="3",
            description="Maximum recovery cycles before ESCALATED",
        ),
        Node(
            package="saltybot_emergency",
            executable="emergency_node",
            name="emergency",
            output="screen",
            parameters=[
                LaunchConfiguration("params_file"),
                {
                    "stop_distance_m": LaunchConfiguration("stop_distance_m"),
                    "max_retries":     LaunchConfiguration("max_retries"),
                },
            ],
        ),
    ])
