import logging

from app.core.config import settings
from app.services import email as email_service
from app.services import sms as sms_service


def test_sms_redacts_otp_outside_development(monkeypatch, caplog):
    monkeypatch.setattr(settings, "environment", "production")
    with caplog.at_level(logging.INFO, logger="yeneb.sms"):
        sms_service.send_sms("+251911223344", "Your Yeneb verification code is 123456.")
    assert "123456" not in caplog.text


def test_sms_logs_otp_in_development(monkeypatch, caplog):
    monkeypatch.setattr(settings, "environment", "development")
    with caplog.at_level(logging.INFO, logger="yeneb.sms"):
        sms_service.send_sms("+251911223344", "Your Yeneb verification code is 123456.")
    assert "123456" in caplog.text


def test_email_redacts_otp_outside_development(monkeypatch, caplog):
    monkeypatch.setattr(settings, "environment", "production")
    with caplog.at_level(logging.INFO, logger="yeneb.email"):
        email_service.send_email(
            "a@example.com",
            "Your code",
            "Your Yeneb verification code is 654321.",
        )
    assert "654321" not in caplog.text


def test_email_logs_otp_in_development(monkeypatch, caplog):
    monkeypatch.setattr(settings, "environment", "development")
    with caplog.at_level(logging.INFO, logger="yeneb.email"):
        email_service.send_email(
            "a@example.com",
            "Your code",
            "Your Yeneb verification code is 654321.",
        )
    assert "654321" in caplog.text
