import logging

from app.config import settings
from app.services.email import get_email_backend

logger = logging.getLogger(__name__)


def send_admin_alert(subject: str, body: str) -> None:
    if not settings.ADMIN_EMAIL:
        logger.warning("ADMIN_EMAIL not set; dropping alert: %s", subject)
        return
    try:
        get_email_backend().send(
            to=settings.ADMIN_EMAIL,
            subject=f"[MealPlanner ALERT] {subject}",
            html=f"<pre>{body}</pre>",
            text=body,
        )
    except Exception:
        logger.exception("Failed to send admin alert: %s", subject)
