use crate::config::{self, ValidationResult};
use crate::db::DbState;
use tauri::State;

#[tauri::command]
pub fn get_config(key: String, state: State<DbState>) -> Result<Option<String>, String> {
    let conn = state.0.lock().map_err(|e| e.to_string())?;
    crate::db::get_config(&conn, &key).map_err(|e| e.to_string())
}

#[tauri::command]
pub fn set_config(key: String, value: String, state: State<DbState>) -> Result<(), String> {
    let conn = state.0.lock().map_err(|e| e.to_string())?;
    crate::db::set_config(&conn, &key, &value).map_err(|e| e.to_string())
}

#[tauri::command]
pub fn validate_uo_root(path: String) -> Result<Vec<ValidationResult>, String> {
    Ok(config::validate_uo_root(&path))
}

#[tauri::command]
pub fn validate_scripts_path(path: String) -> Result<Vec<ValidationResult>, String> {
    Ok(config::validate_scripts_path(&path))
}
