import urllib3
import pytz
import logging
import warnings
import os
from datetime import datetime
from typing import Any, Dict

# --- SILENZIAMENTO IMMEDIATO ---
# Questo agisce prima ancora che 'requests' possa generare warning
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
warnings.filterwarnings("ignore", category=urllib3.exceptions.InsecureRequestWarning)
logging.getLogger("urllib3").setLevel(logging.ERROR)
# Silenzia anche i warning di sklearn/numpy se necessario
os.environ["PYTHONWARNINGS"] = "ignore:Unverified HTTPS request"

# Variabile globale per la Timezone
_current_tz = pytz.UTC

def setup_global_logging(settings: Dict[str, Any]):
    """Configura la Timezone in base al config.yaml."""
    global _current_tz
    debug_cfg = settings.get("debug", {})
    tz_name = debug_cfg.get("timezone", "Europe/Rome")
    try:
        _current_tz = pytz.timezone(tz_name)
    except Exception:
        _current_tz = pytz.UTC

def get_timestamp() -> str:
    """Restituisce il timestamp formattato con la TZ corretta."""
    return datetime.now(_current_tz).strftime('%Y-%m-%dT%H:%M:%S.000Z')

def log_msg(msg: str):
    """Funzione di log standardizzata."""
    print(f"{get_timestamp()} {msg}", flush=True)
