"""Unit tests for TTS service node."""

import unittest
from saltybot_tts_service.tts_service_node import TtsQueueItem


class TestTtsQueueItem(unittest.TestCase):
    """Test TtsQueueItem priority and sorting."""

    def test_queue_item_creation(self):
        """Test creating a TTS queue item."""
        item = TtsQueueItem("Hello world", priority=0)
        self.assertEqual(item.text, "Hello world")
        self.assertEqual(item.priority, 0)
        self.assertFalse(item.interrupt)

    def test_queue_item_priority_sorting(self):
        """Test that items sort by priority (descending) then timestamp (ascending)."""
        import time

        item1 = TtsQueueItem("Low priority", priority=0)
        time.sleep(0.01)  # Ensure different timestamp
        item2 = TtsQueueItem("High priority", priority=1)

        # item2 should be < item1 in priority queue (higher priority = lower value)
        self.assertTrue(item2 < item1)

    def test_queue_item_strips_whitespace(self):
        """Test that text is stripped of whitespace."""
        item = TtsQueueItem("  Hello world  ")
        self.assertEqual(item.text, "Hello world")

    def test_queue_item_interrupt_flag(self):
        """Test interrupt flag."""
        item = TtsQueueItem("Interrupt me", interrupt=True)
        self.assertTrue(item.interrupt)


if __name__ == "__main__":
    unittest.main()
