use serde::Deserialize;
use serde_json::json;

use super::ToolResult;

#[derive(Debug, Default, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct DoctorParams {}

pub async fn execute(_params: DoctorParams) -> ToolResult {
    let session = std::env::var("XDG_SESSION_TYPE").ok();
    let ptrace_scope_warning = envseal::guard::check_ptrace_scope();
    let preload_check = match envseal::guard::check_self_preload() {
        Ok(()) => Some(true),
        Err(_) => Some(false),
    };
    let gui_report = envseal::guard::assess_gui_security();

    Ok(json!({
        "session": session,
        "ptrace_scope_warning": ptrace_scope_warning,
        "self_preload_clean": preload_check,
        "x11_session": gui_report.x11_session,
        "threat_level": format!("{:?}", gui_report.threat_level),
    }))
}
