pub fn get_app_data_dir() -> Result<std::path::PathBuf, String> {
    // attempt to get the app data directory
    match tauri::api::path::data_dir() {
        Some(data_dir) => {
            let app_data_dir = data_dir.join(crate::constants::APP_NAME);
            // ensure the directory exists
            if !app_data_dir.exists() {
                // attempt to create the directory
                std::fs::create_dir_all(&app_data_dir).map_err(|e| {
                    format!(
                        "Failed to create app data directory {:?}: {}",
                        app_data_dir, e
                    )
                })?;
            }
            Ok(app_data_dir)
        }
        None => Err("Failed to get app data directory".to_string()),
    }
}

pub fn get_app_cache_dir() -> Result<std::path::PathBuf, String> {
    // attempt to get the app cache directory
    match tauri::api::path::cache_dir() {
        Some(cache_dir) => {
            let app_cache_dir = cache_dir.join(crate::constants::APP_NAME);
            // ensure the directory exists
            if !app_cache_dir.exists() {
                // attempt to create the directory
                std::fs::create_dir_all(&app_cache_dir).map_err(|e| {
                    format!(
                        "Failed to create app cache directory {:?}: {}",
                        app_cache_dir, e
                    )
                })?;
            }
            Ok(app_cache_dir)
        }
        None => Err("Failed to get app cache directory".to_string()),
    }
}

pub fn get_app_config_dir() -> Result<std::path::PathBuf, String> {
    // attempt to get the app config directory
    match tauri::api::path::config_dir() {
        Some(config_dir) => {
            let app_config_dir = config_dir.join(crate::constants::APP_NAME);
            // ensure the directory exists
            if !app_config_dir.exists() {
                // attempt to create the directory
                std::fs::create_dir_all(&app_config_dir).map_err(|e| {
                    format!(
                        "Failed to create app config directory {:?}: {}",
                        app_config_dir, e
                    )
                })?;
            }
            Ok(app_config_dir)
        }
        None => Err("Failed to get app config directory".to_string()),
    }
}
