"""Kodi host platform helpers for playback/auth behaviour differences."""
from __future__ import annotations

import xbmc

from . import logger


def kodi_platform() -> str:
    return (xbmc.getInfoLabel("System.Platform") or "").strip().lower()


def hls_uses_pipe_auth() -> bool:
    """
    Android/iOS inputstream.adaptive ignores pipe-auth on follow-up requests (401).
    Desktop Kodi (macOS/Linux/Windows) still relies on pipe-auth for protected HLS.
    """
    platform = kodi_platform()
    if platform.startswith("android") or platform.startswith("ios"):
        return False
    return True


def log_playback_platform() -> None:
    os_name = xbmc.getInfoLabel("System.OSName") or "unknown"
    logger.debug(
        f"Playback platform={kodi_platform() or 'unknown'} os={os_name} "
        f"pipe_auth={hls_uses_pipe_auth()}"
    )
