# #region Test.NotificationProvidersExtra [C:3] [TYPE Module] [SEMANTICS test,notification,provider,http-client]
# @BRIEF Additional tests for notifications/providers.py — _get_http_client edge cases.
# @RELATION BINDS_TO -> [providers]

from pathlib import Path
import sys

sys.path.insert(0, str(Path(__file__).parent.parent.parent / "src"))

from unittest.mock import AsyncMock, MagicMock, patch
import pytest


# #region test_get_http_client [C:2] [TYPE Function]
# @BRIEF Test _get_http_client singleton behavior.
class TestGetHttpClient:
    @pytest.mark.asyncio
    async def test_creates_new_client(self):
        from src.services.notifications.providers import _get_http_client, _http_client
        # Reset the singleton
        _http_client = None
        import src.services.notifications.providers as providers_module
        providers_module._http_client = None

        with patch("src.services.notifications.providers.httpx.AsyncClient") as mock_client:
            client = await providers_module._get_http_client()
            assert client is mock_client.return_value
            mock_client.assert_called_once()

    @pytest.mark.asyncio
    async def test_returns_cached_client(self):
        from src.services.notifications.providers import _get_http_client, _http_client
        import src.services.notifications.providers as providers_module
        providers_module._http_client = None

        mock_instance = AsyncMock()
        with patch("src.services.notifications.providers.httpx.AsyncClient", return_value=mock_instance):
            client1 = await providers_module._get_http_client()
            client2 = await providers_module._get_http_client()
            assert client1 is client2  # Same cached instance
# #endregion test_get_http_client

# #endregion Test.NotificationProvidersExtra
