from __future__ import annotations

from datetime import datetime
from typing import Any, MutableMapping
from zoneinfo import ZoneInfo


def force_timezone(dt: datetime, target_tz: ZoneInfo | str) -> datetime:
    """Force a datetime to a specific timezone.

    If naive, localizes it. If aware, converts it.
    """
    if isinstance(target_tz, str):
        target_tz = ZoneInfo(target_tz)

    if dt.tzinfo is None:
        return dt.replace(tzinfo=target_tz)
    return dt.astimezone(target_tz)


def safe_delete(mapping: MutableMapping[str, Any], *keys: str) -> MutableMapping[str, Any]:
    """Remove keys from a mapping if present without raising."""
    for key in keys:
        if key in mapping:
            del mapping[key]
    return mapping
