"""Shared SQL string formatting detection used by both patterns and data_flow."""

from __future__ import annotations

import ast


def is_formatted_sql(node: ast.Call) -> bool:
    """Return True when the first argument shows signs of string formatting.

    Detects f-strings, %-formatting, and .format() calls on the first
    positional argument to a function call (typically cursor.execute).
    """
    if not node.args:
        return False
    first = node.args[0]
    if isinstance(first, ast.JoinedStr):  # f-string
        return True
    if isinstance(first, ast.BinOp) and isinstance(first.op, ast.Mod):  # % formatting
        return True
    if (
        isinstance(first, ast.Call)
        and isinstance(first.func, ast.Attribute)
        and first.func.attr == "format"
    ):
        return True
    return False
