"""camera_hotplug.launch.py — Launch USB camera hot-plug monitor (Issue #320).

Usage:
  ros2 launch saltybot_social camera_hotplug.launch.py
  ros2 launch saltybot_social camera_hotplug.launch.py video_glob:=/dev/video0
  ros2 launch saltybot_social camera_hotplug.launch.py restart_grace_s:=10.0
"""

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", "camera_hotplug_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument("video_glob",      default_value="/dev/video*",
                              description="Glob pattern for video device discovery"),
        DeclareLaunchArgument("poll_rate",       default_value="2.0",
                              description="Device scan frequency (Hz)"),
        DeclareLaunchArgument("restart_grace_s", default_value="5.0",
                              description="Reconnect window that triggers 'restarting' (s)"),

        Node(
            package="saltybot_social",
            executable="camera_hotplug_node",
            name="camera_hotplug_node",
            output="screen",
            parameters=[
                cfg,
                {
                    "video_glob":      LaunchConfiguration("video_glob"),
                    "poll_rate":       LaunchConfiguration("poll_rate"),
                    "restart_grace_s": LaunchConfiguration("restart_grace_s"),
                },
            ],
        ),
    ])
