mod assets;
mod commands;
mod config;
mod db;
mod ipc;

use crate::ipc::sidecar::SidecarState;
use tauri::Manager;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_shell::init())
        .setup(|app| {
            let app_handle = app.handle().clone();
            db::init(&app_handle).expect("Failed to initialize database");
            app.manage(SidecarState::new());
            Ok(())
        })
        .invoke_handler(tauri::generate_handler![
            // Config
            commands::config_commands::get_config,
            commands::config_commands::set_config,
            commands::config_commands::validate_uo_root,
            commands::config_commands::validate_scripts_path,
            // Assets (Phase 1)
            commands::asset_commands::get_static_tile,
            commands::asset_commands::list_static_tiles,
            commands::asset_commands::get_tile_art,
            commands::asset_commands::get_gump_image,
            // Gumps (Phase 4)
            commands::gump_commands::list_gumps,
            commands::gump_commands::get_gump_art,
            commands::gump_commands::list_script_gumps,
            commands::asset_commands::index_assets,
            // Scripts (Phase 2)
            commands::script_commands::index_scripts,
            commands::script_commands::get_script_tree,
            commands::script_commands::get_class_detail,
            commands::script_commands::search_scripts,
            // Flow (Phase 3)
            commands::script_commands::trace_method,
        ])
        .run(tauri::generate_context!())
        .expect("error while running Artificer's Scrollwork");
}
