// Tauri Commands Module
// This module contains all the commands exposed to the frontend

use serde::{Deserialize, Serialize};

/// Common result type for commands
pub type CommandResult<T> = Result<T, String>;

/// Example payload structure
#[derive(Debug, Serialize, Deserialize)]
pub struct ExamplePayload {
    pub data: String,
    pub count: i32,
}

// Basic example command
#[tauri::command]
pub fn greet(name: &str) -> CommandResult<String> {
    Ok(format!("Hello, {}! From Rust backend!", name))
}

// Example with structured payload
#[tauri::command]
pub fn process_data(payload: ExamplePayload) -> CommandResult<String> {
    Ok(format!("Processed: {} (count: {})", payload.data, payload.count))
}

// Async command example
#[tauri::command]
pub async fn async_operation(input: String) -> CommandResult<String> {
    // Simulate async work
    tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
    Ok(format!("Async result from: {}", input))
}

// Error handling example
#[tauri::command]
pub fn command_with_error(should_fail: bool) -> CommandResult<String> {
    if should_fail {
        Err("This command failed as requested".to_string())
    } else {
        Ok("Command succeeded!".to_string())
    }
}

// Complex command with multiple parameters
#[tauri::command]
pub fn complex_command(
    text: String,
    number: i32,
    flag: bool,
) -> CommandResult<String> {
    Ok(format!(
        "Text: {}, Number: {}, Flag: {}",
        text, number, flag
    ))
}

// Export all commands
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    // This function is called on mobile platforms
}
