import unittest
from mindscreen.nlp_analysis import TextAnalyzer


class TestTextAnalyzer(unittest.TestCase):
    def setUp(self):
        self.analyzer = TextAnalyzer()

    def test_positive_sentiment(self):
        f = self.analyzer.analyze("I feel great and happy today, things are good.")
        self.assertGreater(f.sentiment_score, 0)
        self.assertIn("happy", f.positive_hits)

    def test_negative_sentiment_and_depression_markers(self):
        f = self.analyzer.analyze("I feel hopeless and empty, everything is pointless.")
        self.assertLess(f.sentiment_score, 0)
        self.assertIn("hopeless", f.depression_markers)
        self.assertIn("empty", f.depression_markers)

    def test_anxiety_markers(self):
        f = self.analyzer.analyze("I've been so anxious and on edge, I can't relax.")
        self.assertIn("anxious", f.anxiety_markers)
        self.assertIn("on edge", f.anxiety_markers)

    def test_crisis_marker_detected(self):
        f = self.analyzer.analyze("Sometimes I think I want to die.")
        self.assertIn("want to die", f.crisis_markers)

    def test_empty_text_handled(self):
        f = self.analyzer.analyze("")
        self.assertEqual(f.word_count, 0)
        self.assertEqual(f.sentiment_score, 0.0)

    def test_aggregate_across_messages(self):
        msgs = [
            self.analyzer.analyze("I feel anxious and worried."),
            self.analyzer.analyze("Still anxious today, hard to relax."),
        ]
        agg = self.analyzer.aggregate(msgs)
        self.assertEqual(agg["message_count"], 2)
        self.assertGreaterEqual(agg["total_anxiety_markers"], 2)


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