"""
配置管理节点启动文件
Config Node Launch File

启动配置管理节点，从 MySQL 读取配置并发布到 /ai/config topic
"""

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration


def generate_launch_description():
    """生成 launch 描述"""

    # 声明启动参数
    use_mock_data_arg = DeclareLaunchArgument(
        'use_mock_data',
        default_value='true',
        description='是否使用模拟数据 (true/false)'
    )

    refresh_interval_arg = DeclareLaunchArgument(
        'refresh_interval',
        default_value='30.0',
        description='配置刷新间隔 (秒)'
    )

    topic_name_arg = DeclareLaunchArgument(
        'topic_name',
        default_value='/ai/config',
        description='配置发布的话题名称'
    )

    # 定义节点
    config_node = Node(
        package='config_node',
        executable='config_node',
        name='config_node',
        output='screen',
        parameters=[{
            'use_mock_data': LaunchConfiguration('use_mock_data'),
            'refresh_interval': LaunchConfiguration('refresh_interval'),
            'topic_name': LaunchConfiguration('topic_name'),
        }],
    )

    return LaunchDescription([
        use_mock_data_arg,
        refresh_interval_arg,
        topic_name_arg,
        config_node,
    ])
