"""
face_recognition.launch.py -- Launch file for the SCRFD + ArcFace face recognition node.

Launches the face_recognizer node with configurable model paths and parameters.
The RealSense camera must be running separately (e.g., via realsense.launch.py).
"""

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


def generate_launch_description():
    """Generate launch description for face recognition pipeline."""
    return LaunchDescription([
        DeclareLaunchArgument(
            'scrfd_engine_path',
            default_value='/mnt/nvme/saltybot/models/scrfd_2.5g.engine',
            description='Path to SCRFD TensorRT engine file',
        ),
        DeclareLaunchArgument(
            'scrfd_onnx_path',
            default_value='/mnt/nvme/saltybot/models/scrfd_2.5g_bnkps.onnx',
            description='Path to SCRFD ONNX model file (fallback)',
        ),
        DeclareLaunchArgument(
            'arcface_engine_path',
            default_value='/mnt/nvme/saltybot/models/arcface_r50.engine',
            description='Path to ArcFace TensorRT engine file',
        ),
        DeclareLaunchArgument(
            'arcface_onnx_path',
            default_value='/mnt/nvme/saltybot/models/arcface_r50.onnx',
            description='Path to ArcFace ONNX model file (fallback)',
        ),
        DeclareLaunchArgument(
            'gallery_dir',
            default_value='/mnt/nvme/saltybot/gallery',
            description='Directory for persistent face gallery storage',
        ),
        DeclareLaunchArgument(
            'recognition_threshold',
            default_value='0.35',
            description='Cosine similarity threshold for face recognition',
        ),
        DeclareLaunchArgument(
            'publish_debug_image',
            default_value='false',
            description='Publish annotated debug image to /social/faces/debug_image',
        ),
        DeclareLaunchArgument(
            'max_faces',
            default_value='10',
            description='Maximum faces to process per frame',
        ),
        DeclareLaunchArgument(
            'scrfd_conf_thresh',
            default_value='0.5',
            description='SCRFD detection confidence threshold',
        ),

        Node(
            package='saltybot_social_face',
            executable='face_recognition',
            name='face_recognizer',
            output='screen',
            parameters=[{
                'scrfd_engine_path': LaunchConfiguration('scrfd_engine_path'),
                'scrfd_onnx_path': LaunchConfiguration('scrfd_onnx_path'),
                'arcface_engine_path': LaunchConfiguration('arcface_engine_path'),
                'arcface_onnx_path': LaunchConfiguration('arcface_onnx_path'),
                'gallery_dir': LaunchConfiguration('gallery_dir'),
                'recognition_threshold': LaunchConfiguration('recognition_threshold'),
                'publish_debug_image': LaunchConfiguration('publish_debug_image'),
                'max_faces': LaunchConfiguration('max_faces'),
                'scrfd_conf_thresh': LaunchConfiguration('scrfd_conf_thresh'),
            }],
        ),
    ])
