"""rosbag_recorder.launch.py — Launch trigger-based bag recorder (Issue #332).

Usage:
  ros2 launch saltybot_social rosbag_recorder.launch.py
  ros2 launch saltybot_social rosbag_recorder.launch.py auto_stop_s:=120.0
  ros2 launch saltybot_social rosbag_recorder.launch.py \\
      topics:="/saltybot/camera_status,/cmd_vel" bag_dir:=/data/bags
"""

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

    return LaunchDescription([
        DeclareLaunchArgument("topics",       default_value="",
                              description="Comma-separated topics (empty=all)"),
        DeclareLaunchArgument("bag_dir",      default_value="/tmp/saltybot_bags",
                              description="Output directory for bag files"),
        DeclareLaunchArgument("auto_stop_s",  default_value="60.0",
                              description="Auto-stop timeout in seconds (0=off)"),
        DeclareLaunchArgument("compression",  default_value="false",
                              description="Enable zstd compression"),

        Node(
            package="saltybot_social",
            executable="rosbag_recorder_node",
            name="rosbag_recorder_node",
            output="screen",
            parameters=[
                cfg,
                {
                    "topics":      LaunchConfiguration("topics"),
                    "bag_dir":     LaunchConfiguration("bag_dir"),
                    "auto_stop_s": LaunchConfiguration("auto_stop_s"),
                    "compression": LaunchConfiguration("compression"),
                },
            ],
        ),
    ])
