"""
Decorative text checker: strips Zalgo/combining characters and other decorations
to reveal the underlying "42".

Handles: Z̷̧a̶̡l̷̢g̷̡o̶̢ text, combining marks, variation selectors, etc.
Example: ҉4҉҉2҉ → 42
"""

import unicodedata
import re


def _strip_decorations(s):
    """Strip combining characters, zero-width chars, and decorative marks."""
    result = []
    has_decoration = False
    for ch in s:
        cat = unicodedata.category(ch)
        # Skip combining marks (Mn, Mc, Me)
        if cat.startswith("M"):
            has_decoration = True
            continue
        # Skip zero-width characters
        if cat in ("Cf", "Cc") and ch not in ("\n", "\r", "\t"):
            has_decoration = True
            continue
        # Skip variation selectors (U+FE00-U+FE0F, U+E0100-U+E01EF)
        if "\ufe00" <= ch <= "\ufe0f":
            has_decoration = True
            continue
        # Skip specific decorative characters
        if ch in "\u0489\u0488":  # ҉ (Combining Cyrillic Millions Sign, etc.)
            has_decoration = True
            continue
        result.append(ch)

    return "".join(result), has_decoration


def check(value):
    """Check if value is 42 hidden under decorative/Zalgo characters."""
    if not isinstance(value, str):
        return None

    s = value.strip()
    if not s:
        return None

    stripped, had_decoration = _strip_decorations(s)
    if not had_decoration:
        return None

    stripped = stripped.strip()
    if not stripped:
        return None

    # Check if the stripped result is "42"
    if stripped == "42":
        return f"decorated text: stripped to '42' from Zalgo/combining characters"

    return None
