"""
Basic tests for gesture recognition.
"""

import pytest
import numpy as np

try:
    from saltybot_gesture_recognition.gesture_recognition_node import GestureDetector
    _DETECTOR_OK = True
except ImportError:
    _DETECTOR_OK = False


@pytest.mark.skipif(not _DETECTOR_OK, reason="GestureDetector not available")
class TestGestureDetector:
    """Tests for gesture detection."""

    def test_detector_init(self):
        """Test GestureDetector initialization."""
        try:
            detector = GestureDetector(enable_gpu=False)
            assert detector is not None
        except ImportError:
            pytest.skip("MediaPipe not available")

    def test_hand_gesture_detection_empty(self):
        """Test hand gesture detection with empty frame."""
        try:
            detector = GestureDetector(enable_gpu=False)
            gestures = detector.detect_hand_gestures(None)
            assert gestures == []
        except ImportError:
            pytest.skip("MediaPipe not available")

    def test_body_gesture_detection_empty(self):
        """Test body gesture detection with empty frame."""
        try:
            detector = GestureDetector(enable_gpu=False)
            gestures = detector.detect_body_gestures(None)
            assert gestures == []
        except ImportError:
            pytest.skip("MediaPipe not available")

    def test_hand_gesture_detection_frame(self):
        """Test hand gesture detection with synthetic frame."""
        try:
            detector = GestureDetector(enable_gpu=False)
            # Create a blank frame
            frame = np.zeros((480, 640, 3), dtype=np.uint8)
            gestures = detector.detect_hand_gestures(frame)
            # May or may not detect anything in blank frame
            assert isinstance(gestures, list)
        except ImportError:
            pytest.skip("MediaPipe not available")


class TestGestureMessages:
    """Basic Gesture message tests."""

    def test_gesture_creation(self):
        """Test creating a Gesture message."""
        try:
            from saltybot_social_msgs.msg import Gesture
            g = Gesture()
            g.gesture_type = 'wave'
            g.confidence = 0.85
            assert g.gesture_type == 'wave'
            assert g.confidence == 0.85
        except ImportError:
            pytest.skip("saltybot_social_msgs not built")

    def test_gesture_array_creation(self):
        """Test creating a GestureArray message."""
        try:
            from saltybot_social_msgs.msg import Gesture, GestureArray
            arr = GestureArray()
            g = Gesture()
            g.gesture_type = 'point'
            arr.gestures.append(g)
            arr.count = 1
            assert arr.count == 1
            assert arr.gestures[0].gesture_type == 'point'
        except ImportError:
            pytest.skip("saltybot_social_msgs not built")


if __name__ == '__main__':
    pytest.main([__file__])
