"""Launch file for diagnostics aggregator 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_diagnostics_aggregator")
    config_file = os.path.join(pkg_dir, "config", "aggregator_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument(
            "config_file",
            default_value=config_file,
            description="Path to aggregator_params.yaml",
        ),
        DeclareLaunchArgument(
            "heartbeat_hz",
            default_value="1.0",
            description="Publish rate for /saltybot/system_health (Hz)",
        ),
        DeclareLaunchArgument(
            "stale_timeout_s",
            default_value="5.0",
            description="Seconds without update before subsystem goes STALE",
        ),
        Node(
            package="saltybot_diagnostics_aggregator",
            executable="diagnostics_aggregator_node",
            name="diagnostics_aggregator",
            output="screen",
            parameters=[
                LaunchConfiguration("config_file"),
                {
                    "heartbeat_hz":    LaunchConfiguration("heartbeat_hz"),
                    "stale_timeout_s": LaunchConfiguration("stale_timeout_s"),
                },
            ],
        ),
    ])
