use crate::commands::prelude::*;
use tauri::{AppHandle, State};

#[tauri::command]
#[specta::specta]
pub async fn mcp_status(
    config: State<'_, GuiConfigState>,
    mcp: State<'_, crate::mcp::McpState>,
) -> Result<crate::mcp::McpStatus, RustError> {
    Ok(mcp.status(config.get().mcp_enabled).await)
}

#[tauri::command]
#[specta::specta]
pub async fn mcp_set_enabled(
    app: AppHandle,
    config: State<'_, GuiConfigState>,
    mcp: State<'_, crate::mcp::McpState>,
    enabled: bool,
) -> Result<crate::mcp::McpStatus, RustError> {
    {
        let mut config = config.load_mut().await?;
        config.mcp_enabled = enabled;
        config.save().await?;
    }

    mcp.set_enabled(app, enabled).await?;
    Ok(mcp.status(enabled).await)
}
