from collections.abc import Mapping

from ..client import AbuseIPDB
from ..constants import AbuseCategory
from ..exceptions import AbuseIPDBError
from ..responses import ReportResponse


def report_suspicious_operation(
    client: AbuseIPDB,
    ip_address: str,
    parameters: Mapping[str, object],
) -> ReportResponse | None:
    """Report framework-supplied suspicious request context, swallowing SDK failures."""
    rendered = "".join(f"{name}: {value}\n" for name, value in parameters.items())
    comment = f"Suspicious Operation. Request content:\n{rendered}"
    try:
        return client.report(
            ip_address,
            AbuseCategory.WEB_APP_ATTACK,
            comment=comment,
        )
    except AbuseIPDBError:
        return None
