"""
social.launch.py — Launch the full saltybot social stack.

Includes:
  person_state_tracker — multi-modal person identity fusion (Issue #82)
  expression_node      — /social/mood → ESP32-C3 NeoPixel serial (Issue #86)
  attention_node       — /social/persons → /cmd_vel rotation (Issue #86)

Usage:
  ros2 launch saltybot_social social.launch.py
  ros2 launch saltybot_social social.launch.py serial_port:=/dev/ttyUSB1
"""

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 = get_package_share_directory("saltybot_social")
    exp_cfg = os.path.join(pkg, "config", "expression_params.yaml")
    att_cfg = os.path.join(pkg, "config", "attention_params.yaml")

    return LaunchDescription([
        # person_state_tracker args (Issue #82)
        DeclareLaunchArgument(
            'engagement_distance',
            default_value='2.0',
            description='Distance in metres below which a person is considered engaged'
        ),
        DeclareLaunchArgument(
            'absent_timeout',
            default_value='5.0',
            description='Seconds without detection before marking person as ABSENT'
        ),
        DeclareLaunchArgument(
            'uwb_enabled',
            default_value='false',
            description='Whether UWB anchor data is available'
        ),

        # expression_node args (Issue #86)
        DeclareLaunchArgument("serial_port",    default_value="/dev/esp32-social"),
        DeclareLaunchArgument("baud_rate",      default_value="115200"),
        DeclareLaunchArgument("idle_timeout_s", default_value="3.0"),

        # attention_node args (Issue #86)
        DeclareLaunchArgument("kp_angular",       default_value="1.0"),
        DeclareLaunchArgument("max_angular_vel",  default_value="0.8"),
        DeclareLaunchArgument("dead_zone_rad",     default_value="0.15"),
        DeclareLaunchArgument("lost_timeout_s",    default_value="2.0"),
        DeclareLaunchArgument("attention_enabled", default_value="true"),

        Node(
            package='saltybot_social',
            executable='person_state_tracker',
            name='person_state_tracker',
            output='screen',
            parameters=[{
                'engagement_distance': LaunchConfiguration('engagement_distance'),
                'absent_timeout': LaunchConfiguration('absent_timeout'),
                'uwb_enabled': LaunchConfiguration('uwb_enabled'),
            }],
        ),

        Node(
            package="saltybot_social",
            executable="expression_node",
            name="expression_node",
            output="screen",
            parameters=[
                exp_cfg,
                {
                    "serial_port":    LaunchConfiguration("serial_port"),
                    "baud_rate":      LaunchConfiguration("baud_rate"),
                    "idle_timeout_s": LaunchConfiguration("idle_timeout_s"),
                },
            ],
        ),

        Node(
            package="saltybot_social",
            executable="attention_node",
            name="attention_node",
            output="screen",
            parameters=[
                att_cfg,
                {
                    "kp_angular":       LaunchConfiguration("kp_angular"),
                    "max_angular_vel":  LaunchConfiguration("max_angular_vel"),
                    "dead_zone_rad":    LaunchConfiguration("dead_zone_rad"),
                    "lost_timeout_s":   LaunchConfiguration("lost_timeout_s"),
                    "attention_enabled": LaunchConfiguration("attention_enabled"),
                },
            ],
        ),
    ])
