"""Tests for caffeinate_me.core."""

from unittest.mock import patch

import pytest

from caffeinate_me.core import caffeinate_me, strip_emoji


class TestCaffeinateMe:
    def test_returns_string(self):
        assert isinstance(caffeinate_me(), str)

    def test_always_returns_non_empty(self):
        for _ in range(20):
            result = caffeinate_me()
            assert result and result.strip()

    def test_coffee_path(self):
        with patch("caffeinate_me.core.random") as mock_rng:
            mock_rng.random.return_value = 0.0  # always < 0.8 → coffee
            result = caffeinate_me()
        assert "cup" in result.lower()

    def test_nap_path(self):
        with patch("caffeinate_me.core.random") as mock_rng:
            mock_rng.random.return_value = 0.99  # always >= 0.8 → nap
            result = caffeinate_me()
        assert "nap" in result.lower()

    @pytest.mark.parametrize("mood", ["energetic", "sleepy", "stressed", "zen"])
    def test_valid_moods(self, mood):
        result = caffeinate_me(mood=mood)
        assert isinstance(result, str) and result.strip()

    def test_invalid_mood_still_returns_string(self):
        result = caffeinate_me(mood="turbo")
        assert isinstance(result, str)

    def test_no_emoji_strips_coffee_cup(self):
        with patch("caffeinate_me.core.random") as mock_rng:
            # Force the "nap" path so we know the emoji that would appear.
            mock_rng.random.return_value = 0.99
            result = caffeinate_me(no_emoji=True)
        # The thinking emoji \U0001f914 should be gone.
        assert "\U0001f914" not in result
        assert "nap" in result.lower()

    def test_no_emoji_keeps_text(self):
        with patch("caffeinate_me.core.random") as mock_rng:
            mock_rng.random.return_value = 0.0
            result = caffeinate_me(no_emoji=True)
        assert "cup" in result.lower()

    def test_randomness_produces_variety(self):
        results = {caffeinate_me() for _ in range(50)}
        assert len(results) > 1


class TestStripEmoji:
    def test_removes_coffee_cup(self):
        assert "\u2615" not in strip_emoji("Hello \u2615 World")

    def test_removes_thinking_face(self):
        assert "\U0001f914" not in strip_emoji("Hmm \U0001f914")

    def test_preserves_plain_text(self):
        result = strip_emoji("Hello World")
        assert "Hello" in result
        assert "World" in result

    def test_empty_string(self):
        assert strip_emoji("") == ""

    def test_only_emoji_becomes_empty(self):
        assert strip_emoji("\u2615\U0001f914\U0001f389").strip() == ""
