"""
docking.launch.py — Launch the autonomous docking node (Issue #158).

Usage
-----
  ros2 launch saltybot_docking docking.launch.py
  ros2 launch saltybot_docking docking.launch.py \
      battery_low_pct:=15.0 servo_range_m:=1.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_share = get_package_share_directory("saltybot_docking")
    default_params = os.path.join(pkg_share, "config", "docking_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument(
            "params_file",
            default_value=default_params,
            description="Path to docking_params.yaml",
        ),
        DeclareLaunchArgument(
            "battery_low_pct",
            default_value="15.0",
            description="SOC threshold to trigger auto-dock (%)",
        ),
        DeclareLaunchArgument(
            "servo_range_m",
            default_value="1.0",
            description="Switch to visual servo within this distance (m)",
        ),
        Node(
            package="saltybot_docking",
            executable="docking_node",
            name="docking",
            output="screen",
            parameters=[
                LaunchConfiguration("params_file"),
                {
                    "battery_low_pct": LaunchConfiguration("battery_low_pct"),
                    "servo_range_m":   LaunchConfiguration("servo_range_m"),
                },
            ],
        ),
    ])
