"""Launch file for VESC CAN health monitor node."""

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("saltybot_vesc_health")
    config_file = os.path.join(pkg_dir, "config", "vesc_health_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument(
            "config_file",
            default_value=config_file,
            description="Path to vesc_health_params.yaml",
        ),
        DeclareLaunchArgument(
            "can_interface",
            default_value="can0",
            description="SocketCAN interface name",
        ),
        DeclareLaunchArgument(
            "frame_timeout_s",
            default_value="0.5",
            description="Frame-drop detection threshold (s)",
        ),
        DeclareLaunchArgument(
            "estop_timeout_s",
            default_value="2.0",
            description="E-stop escalation threshold (s from last good frame)",
        ),
        Node(
            package="saltybot_vesc_health",
            executable="vesc_health_node",
            name="vesc_health_monitor",
            output="screen",
            parameters=[
                LaunchConfiguration("config_file"),
                {
                    "can_interface":  LaunchConfiguration("can_interface"),
                    "frame_timeout_s": LaunchConfiguration("frame_timeout_s"),
                    "estop_timeout_s": LaunchConfiguration("estop_timeout_s"),
                },
            ],
        ),
    ])
