# Low-battery notifications (nomarchy.batteryNotify) — the bar colors the
# battery @warn/@bad at 25/10% (waybar.nix battery.states) but nothing
# *notified*; this watcher fires a toast at those same thresholds. Session-
# side and self-gating on a battery being present (the powerprofile-script
# pattern — no system→home coupling), so it's a silent no-op on desktops.
# swaync shows critical toasts until dismissed (timeout-critical = 0), so
# the 10% one can't slip by unseen. Logic lives in pkgs/nomarchy-battery-
# notify (overlay), where checks.battery-notify exercises it.
{ config, lib, pkgs, ... }:

{
  config = lib.mkIf config.nomarchy.batteryNotify.enable {
    systemd.user.services.nomarchy-battery-notify = {
      Unit = {
        Description = "Low-battery notifications (25/10%, the bar's thresholds)";
        PartOf = [ "graphical-session.target" ];
        After = [ "graphical-session.target" ];
      };
      Service = {
        # The script resolves notify-send from PATH (that's what the VM
        # check shims); here libnotify provides the real one.
        Environment = "PATH=${lib.makeBinPath [ pkgs.libnotify ]}";
        ExecStart = "${pkgs.nomarchy-battery-notify}/bin/nomarchy-battery-notify";
        Restart = "on-failure";
      };
      Install.WantedBy = [ "graphical-session.target" ];
    };
  };
}
