use crate::types::Settings;
use std::sync::Mutex;
use tauri::State;

/// State wrapper for settings.
pub struct SettingsState(pub Mutex<Settings>);

/// Get the current settings.
#[tauri::command]
pub async fn get_settings(state: State<'_, SettingsState>) -> Result<Settings, String> {
    let settings = state.0.lock().map_err(|e| e.to_string())?;
    Ok(settings.clone())
}

/// Update the settings.
#[tauri::command]
pub async fn update_settings(
    state: State<'_, SettingsState>,
    settings: Settings,
) -> Result<(), String> {
    let mut current = state.0.lock().map_err(|e| e.to_string())?;
    *current = settings;
    tracing::info!("Settings updated");
    Ok(())
}
