"""mesh.launch.py — Launch the social mesh comms node (Issue #171).

Usage:
  ros2 launch saltybot_social mesh.launch.py
  ros2 launch saltybot_social mesh.launch.py robot_id:=saltybot_2
"""

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 = get_package_share_directory("saltybot_social")
    cfg = os.path.join(pkg, "config", "mesh_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument(
            "robot_id",
            default_value=os.environ.get("ROBOT_ID", "saltybot_1"),
            description="Unique robot identifier for mesh announcements",
        ),
        DeclareLaunchArgument(
            "announce_rate_hz",
            default_value="1.0",
            description="Heartbeat rate (Hz)",
        ),
        DeclareLaunchArgument(
            "peer_timeout_s",
            default_value="5.0",
            description="Seconds before a peer is considered lost",
        ),

        Node(
            package="saltybot_social",
            executable="mesh_comms_node",
            name="mesh_comms_node",
            output="screen",
            parameters=[
                cfg,
                {
                    "robot_id":          LaunchConfiguration("robot_id"),
                    "announce_rate_hz":  LaunchConfiguration("announce_rate_hz"),
                    "peer_timeout_s":    LaunchConfiguration("peer_timeout_s"),
                },
            ],
        ),
    ])
