"""Launch file for saltybot_uwb_position (Issue #546)."""

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() -> LaunchDescription:
    config_path = os.path.join(
        get_package_share_directory("saltybot_uwb_position"),
        "config",
        "uwb_position_params.yaml",
    )

    port_arg = DeclareLaunchArgument(
        "serial_port",
        default_value="/dev/ttyUSB0",
        description="USB serial port for ESP32 UWB tag (e.g. /dev/ttyUWB_TAG)",
    )

    uwb_node = Node(
        package="saltybot_uwb_position",
        executable="uwb_position",
        name="uwb_position",
        parameters=[
            config_path,
            {"serial_port": LaunchConfiguration("serial_port")},
        ],
        output="screen",
    )

    return LaunchDescription([port_arg, uwb_node])
