"""Numerical value detection and shared numeric constants."""

from __future__ import annotations

from decimal import Decimal
from typing import Any

# Canonical numeric type tuple — use this instead of (int, float) everywhere.
# COM/win32com may return Decimal for currency or high-precision cells.
NUMERIC_TYPES = (int, float, Decimal)

# Canonical currency symbol list — shared between categorize.py (detection)
# and format.py (display).  Keep as tuple for categorize and as regex for format.
CURRENCY_CHARS = ('$', '£', '€', '¥', '₹', '₩', '₪', '₱', '฿', 'kr')
CURRENCY_RE = r'[$\xa3\u20ac\xa5\u20b9\u20a9\u20aa\u20b1\u0e3f]|kr'


def is_numerical(value: Any) -> bool:
    """Return True if *value* looks like a number (for context filtering)."""
    if isinstance(value, NUMERIC_TYPES):
        return True
    if isinstance(value, str):
        v = value.strip()
        if v == '':
            return False
        try:
            float(v)
            return True
        except (ValueError, OverflowError):
            return False
    return False
