"""vad.launch.py — Launch the energy+ZCR VAD node (Issue #242).

Usage:
  ros2 launch saltybot_social vad.launch.py
  ros2 launch saltybot_social vad.launch.py rms_threshold_db:=-40.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", "vad_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument("rms_threshold_db", default_value="-35.0",
                              description="Energy gate in dBFS"),
        DeclareLaunchArgument("zcr_min",          default_value="0.01",
                              description="ZCR lower bound"),
        DeclareLaunchArgument("zcr_max",          default_value="0.40",
                              description="ZCR upper bound"),
        DeclareLaunchArgument("onset_frames",     default_value="2",
                              description="Onset hysteresis frames"),
        DeclareLaunchArgument("offset_frames",    default_value="8",
                              description="Offset hysteresis frames"),

        Node(
            package="saltybot_social",
            executable="vad_node",
            name="vad_node",
            output="screen",
            parameters=[
                cfg,
                {
                    "rms_threshold_db": LaunchConfiguration("rms_threshold_db"),
                    "zcr_min":          LaunchConfiguration("zcr_min"),
                    "zcr_max":          LaunchConfiguration("zcr_max"),
                    "onset_frames":     LaunchConfiguration("onset_frames"),
                    "offset_frames":    LaunchConfiguration("offset_frames"),
                },
            ],
        ),
    ])
