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_dir = get_package_share_directory("planner")
    params_file = LaunchConfiguration(
        "params_file",
        default=os.path.join(pkg_dir, "config", "pure_pursuit_tracker.yaml"),
    )
    use_sim_time = LaunchConfiguration("use_sim_time", default="false")

    tracker_node = Node(
        package="planner",
        executable="topology_pure_pursuit_node.py",
        name="topology_pure_pursuit",
        output="screen",
        parameters=[
            params_file,
            {"use_sim_time": use_sim_time},
        ],
    )

    return LaunchDescription(
        [
            DeclareLaunchArgument(
                "params_file",
                default_value=os.path.join(
                    pkg_dir, "config", "pure_pursuit_tracker.yaml"
                ),
                description="Parameters for Pure Pursuit tracker-only mode.",
            ),
            DeclareLaunchArgument(
                "use_sim_time",
                default_value="false",
                description="Use simulation clock.",
            ),
            tracker_node,
        ]
    )
