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


def generate_launch_description():
    xlm_sdk_root = '/home/sunrise/opt/dev/bigmodel/LLM_S100/D-Robotics_LLM_S100_1.0.0_SDK/oellm_runtime'
    ld_library_path = f'{xlm_sdk_root}/lib:$LD_LIBRARY_PATH'

    return LaunchDescription([
        DeclareLaunchArgument('config_path', default_value='config/omni_config.json',
                              description='Path to omni_config.json'),
        DeclareLaunchArgument('node_name', default_value='omni_node',
                              description='Name of the node'),
        DeclareLaunchArgument('xlm_sdk_root', default_value=xlm_sdk_root,
                              description='Path to xlm SDK'),
        DeclareLaunchArgument('enable_legacy_asr_mode', default_value='false',
                              description='Enable legacy /asr -> /llm_response mode'),
        DeclareLaunchArgument('enable_planner_mode', default_value='true',
                              description='Enable planner orchestrated mode'),

        Node(
            package='omni_node',
            executable='omni_node',
            name=LaunchConfiguration('node_name'),
            output='screen',
            parameters=[
                {'config_path': LaunchConfiguration('config_path')},
                {'enable_legacy_asr_mode': LaunchConfiguration('enable_legacy_asr_mode')},
                {'enable_planner_mode': LaunchConfiguration('enable_planner_mode')},
            ],
            remappings=[
                ('/llm_response', 'llm_response'),
                ('/planner/llm_request', 'planner/llm_request'),
                ('/planner/llm_response', 'planner/llm_response'),
            ],
            env={
                'LD_LIBRARY_PATH': f'{xlm_sdk_root}/lib:/opt/ros/humble/lib:$LD_LIBRARY_PATH',
                'ROS_HOME': '/home/sunrise/.ros',
                'ROS_LOG_DIR': '/home/sunrise/.ros/log',
            },
        ),
    ])

