"""Launch file for accessibility mode on MageDok 7in display."""

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration
from launch.actions import DeclareLaunchArgument
import os
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    """Generate launch description for accessibility mode."""
    pkg_dir = get_package_share_directory("saltybot_accessibility_mode")
    config_file = os.path.join(
        pkg_dir, "config", "accessibility_params.yaml"
    )

    return LaunchDescription(
        [
            DeclareLaunchArgument(
                "config_file",
                default_value=config_file,
                description="Path to configuration YAML file",
            ),
            DeclareLaunchArgument(
                "ui_port",
                default_value="8080",
                description="Port for UI server (MageDok display)",
            ),
            # Accessibility mode coordinator node
            Node(
                package="saltybot_accessibility_mode",
                executable="accessibility_mode_node",
                name="accessibility_mode",
                output="screen",
                parameters=[LaunchConfiguration("config_file")],
                remappings=[
                    ("/social/speech/transcript", "/social/speech/transcript"),
                    ("/accessibility/keyboard_input", "/accessibility/keyboard_input"),
                    ("/social/conversation/request", "/social/conversation/request"),
                ],
            ),
            # Web UI server for touch keyboard and STT display
            Node(
                package="saltybot_accessibility_mode",
                executable="ui_server",
                name="accessibility_ui",
                output="screen",
                parameters=[
                    {"port": LaunchConfiguration("ui_port")},
                ],
            ),
        ]
    )
