"""Fixtures compartilhadas para os testes do pack-mcp-google-chat-notification."""

import os
import pytest


@pytest.fixture(autouse=True)
def clean_env(monkeypatch):
    """Remove variáveis de ambiente do Google Chat antes de cada teste."""
    monkeypatch.delenv("GOOGLE_CHAT_WEBHOOK_URL", raising=False)
    monkeypatch.delenv("LOG_LEVEL", raising=False)


@pytest.fixture
def mock_webhook_url():
    """URL de webhook válida para testes."""
    return "https://chat.googleapis.com/v1/spaces/test/messages?key=testkey&token=testtoken"


@pytest.fixture
def mock_env_webhook(monkeypatch, mock_webhook_url):
    """Define GOOGLE_CHAT_WEBHOOK_URL como variável de ambiente."""
    monkeypatch.setenv("GOOGLE_CHAT_WEBHOOK_URL", mock_webhook_url)
    return mock_webhook_url


@pytest.fixture(autouse=True)
def reset_singleton():
    """Reset do singleton do GoogleChatClient antes e depois de cada teste."""
    try:
        from pack_mcp_google_chat_notification.client import GoogleChatClient
        GoogleChatClient.reset()
        yield
        GoogleChatClient.reset()
    except ImportError:
        yield
