"""
AC power detection for macOS.

Uses pmset to determine whether the machine is on AC power.
Training should only run when plugged in (on laptops).
Desktops always report AC.
"""
from __future__ import annotations

import subprocess


def is_ac_powered() -> bool:
    """Return True if the machine is on AC power, False if on battery or unknown."""
    try:
        result = subprocess.run(
            ["pmset", "-g", "ps"],
            capture_output=True,
            text=True,
            timeout=5,
        )
        return "AC Power" in (result.stdout or "")
    except Exception:
        return False
