from typing import Dict,Optional, Tuple

_CF_TOKENS = (
    "One moment, please...",
    "Please wait while your request is being verified",
    "/cdn-cgi/challenge-platform/",
    "rocket-loader.min.js",
)

def _looks_like_cf_html(html: Optional[str]) -> Tuple[bool, Optional[str]]:
    if not html:
        return False, None
    for tok in _CF_TOKENS:
        if tok in html:
            return True, tok
    return False, None

def _product_dict_is_cf(d: Dict) -> Tuple[bool, Optional[str]]:
    title = (d.get("title") or "").strip()
    if title.lower() == "one moment, please...":
        return True, "One moment, please..."
    ok, tok = _looks_like_cf_html(d.get("description_html"))
    if ok:
        return True, tok
    for sec in d.get("sections") or []:
        if isinstance(sec, dict) and sec.get("html"):
            ok2, tok2 = _looks_like_cf_html(sec["html"])
            if ok2:
                return True, tok2
    if not d.get("images") and not d.get("description_html") and not d.get("sections"):
        return True, "all_empty_heuristic"
    return False, None
