from __future__ import annotations

from datetime import datetime
import platform
import socket


ALLOWED_METADATA_FIELDS = (
    "os_name",
    "os_version",
    "hostname",
    "timezone",
    "app_version",
    "device_type",
)


def collect_safe_metadata(*, app_version: str, device_type: str) -> dict[str, str]:
    tz = datetime.now().astimezone().tzinfo
    timezone_value = str(tz) if tz else "UTC"
    data = {
        "os_name": platform.system() or "unknown",
        "os_version": platform.release() or "unknown",
        "hostname": socket.gethostname() or "unknown",
        "timezone": timezone_value,
        "app_version": app_version,
        "device_type": device_type,
    }
    return {k: data[k] for k in ALLOWED_METADATA_FIELDS}
