import hashlib from typing import Any # Responsabilidade: utilitários genéricos reutilizáveis do domínio def parse_float(value: Any, default: float = 0.0) -> float: if value is None: return default if isinstance(value, (int, float)): return float(value) text = str(value).replace("R$", "").replace(" ", "") text = text.replace(".", "").replace(",", ".") if "," in text else text try: return float(text) except Exception: return default def parse_bool(value: Any, default: bool = False) -> bool: if isinstance(value, bool): return value if value is None: return default text = str(value).strip().lower() if text in {"true", "1", "sim", "yes", "y"}: return True if text in {"false", "0", "nao", "no", "n"}: return False return default def stable_int(seed_text: str) -> int: digest = hashlib.sha256(seed_text.encode("utf-8")).hexdigest() return int(digest[:16], 16) def is_legacy_schema_issue(exc: Exception) -> bool: lowered = str(exc).lower() return ( "unknown column" in lowered or "invalid column" in lowered or "has no column named" in lowered or "no such column" in lowered or "column count doesn't match" in lowered )