use std::path::Path;
use tokio::process::Command;

/// Build a `tokio::process::Command` that runs `target` with elevated
/// privileges via `pkexec`. The caller is responsible for setting stdio,
/// kill_on_drop, etc.
pub fn elevated(target: &Path, args: &[String]) -> Command {
    let mut cmd = Command::new("pkexec");
    cmd.arg(target);
    for a in args {
        cmd.arg(a);
    }
    cmd
}

/// pkexec exit codes worth surfacing distinctly.
///
///   126 — authorization could not be obtained (user cancelled the dialog,
///         no agent available, or polkit policy denied).
///   127 — command was not found / not authorized.
///
/// Anything else is forwarded as-is and the supervisor will translate it
/// into `SidecarExited`.
pub fn is_auth_failure(code: i32) -> bool {
    matches!(code, 126 | 127)
}
