"""Tests for configuration loading."""
import importlib
import os


def test_config_reads_api_key_from_environment(monkeypatch):
    monkeypatch.setenv("RELAYWAY_API_KEY", "sk_test_123")
    import relayway.config as config
    reloaded = importlib.reload(config)
    assert reloaded.API_KEY == "sk_test_123"


def test_config_reads_webhook_secret_from_environment(monkeypatch):
    monkeypatch.setenv("RELAYWAY_WEBHOOK_SECRET", "whsec_test_456")
    import relayway.config as config
    reloaded = importlib.reload(config)
    assert reloaded.WEBHOOK_SECRET == "whsec_test_456"


def test_config_reads_base_url_from_environment(monkeypatch):
    monkeypatch.setenv("RELAYWAY_BASE_URL", "https://api.relayway.com")
    import relayway.config as config
    reloaded = importlib.reload(config)
    assert reloaded.BASE_URL == "https://api.relayway.com"


def test_config_base_url_defaults_when_not_set(monkeypatch):
    monkeypatch.delenv("RELAYWAY_BASE_URL", raising=False)
    import relayway.config as config
    reloaded = importlib.reload(config)
    assert reloaded.BASE_URL == "http://localhost:8000"


def test_config_api_key_is_none_when_not_set(monkeypatch):
    monkeypatch.delenv("RELAYWAY_API_KEY", raising=False)
    import relayway.config as config
    reloaded = importlib.reload(config)
    assert reloaded.API_KEY is None


def test_config_webhook_secret_is_none_when_not_set(monkeypatch):
    monkeypatch.delenv("RELAYWAY_WEBHOOK_SECRET", raising=False)
    import relayway.config as config
    reloaded = importlib.reload(config)
    assert reloaded.WEBHOOK_SECRET is None
