"""volume_adjust.launch.py — Launch speech volume auto-adjuster (Issue #289).

Usage:
  ros2 launch saltybot_social volume_adjust.launch.py
  ros2 launch saltybot_social volume_adjust.launch.py min_volume:=0.3 max_volume:=0.9
"""

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

    return LaunchDescription([
        DeclareLaunchArgument("min_volume",  default_value="0.5",
                              description="Quietest TTS volume [0..1]"),
        DeclareLaunchArgument("max_volume",  default_value="1.0",
                              description="Loudest TTS volume [0..1]"),
        DeclareLaunchArgument("curve_gamma", default_value="0.5",
                              description="Power-curve exponent (0.5=concave, 1=linear, 2=convex)"),
        DeclareLaunchArgument("smoothing_alpha", default_value="0.1",
                              description="EMA smoothing factor (0=frozen, 1=instant)"),

        Node(
            package="saltybot_social",
            executable="volume_adjust_node",
            name="volume_adjust_node",
            output="screen",
            parameters=[
                cfg,
                {
                    "min_volume":      LaunchConfiguration("min_volume"),
                    "max_volume":      LaunchConfiguration("max_volume"),
                    "curve_gamma":     LaunchConfiguration("curve_gamma"),
                    "smoothing_alpha": LaunchConfiguration("smoothing_alpha"),
                },
            ],
        ),
    ])
