pub mod api;
pub mod commands;
pub mod elevation;
pub mod error;
pub mod poller;
pub mod sidecar;
pub mod state;

use state::AppState;
use tauri::Manager;
use tracing_subscriber::EnvFilter;

pub fn run() {
    tracing_subscriber::fmt()
        .with_env_filter(
            EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
        )
        .with_target(false)
        .compact()
        .try_init()
        .ok();

    tauri::Builder::default()
        .plugin(tauri_plugin_store::Builder::new().build())
        .plugin(tauri_plugin_shell::init())
        .plugin(tauri_plugin_dialog::init())
        .setup(|app| {
            app.manage(AppState::new());
            Ok(())
        })
        .invoke_handler(tauri::generate_handler![
            commands::daemon_status,
            commands::start_daemon,
            commands::stop_daemon,
            commands::node_info,
            commands::sidecar_logs,
            commands::peers_list,
            commands::peer_add,
            commands::peer_remove,
            commands::peers_stats,
            commands::routes_snapshot,
            commands::send_message,
            commands::reply_message,
            commands::message_status,
            commands::inbox_messages,
            commands::inbox_clear,
            commands::topics_default_get,
            commands::topics_default_set,
            commands::topics_list,
            commands::topic_add,
            commands::topic_remove,
            commands::topic_sources_list,
            commands::topic_source_add,
            commands::topic_source_remove,
            commands::topic_forward_get,
            commands::topic_forward_set,
            commands::topic_forward_remove,
            commands::lookup_pubkey,
            commands::regenerate_identity,
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
