"""sensor_health.launch.py — Launch sensor health monitor node (Issue #566)."""

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:
    pkg = get_package_share_directory("saltybot_health_monitor")

    check_hz_arg = DeclareLaunchArgument(
        "check_hz",
        default_value="1.0",
        description="Health check publish rate (Hz)",
    )
    mqtt_broker_arg = DeclareLaunchArgument(
        "mqtt_broker",
        default_value="localhost",
        description="MQTT broker hostname",
    )
    mqtt_enabled_arg = DeclareLaunchArgument(
        "mqtt_enabled",
        default_value="true",
        description="Enable MQTT publishing to saltybot/health",
    )

    sensor_health_node = Node(
        package="saltybot_health_monitor",
        executable="sensor_health_node",
        name="sensor_health_node",
        output="screen",
        parameters=[
            os.path.join(pkg, "config", "sensor_health_params.yaml"),
            {
                "check_hz":    LaunchConfiguration("check_hz"),
                "mqtt_broker": LaunchConfiguration("mqtt_broker"),
                "mqtt_enabled": LaunchConfiguration("mqtt_enabled"),
            },
        ],
    )

    return LaunchDescription([
        check_hz_arg,
        mqtt_broker_arg,
        mqtt_enabled_arg,
        sensor_health_node,
    ])
