use crate::commands::{
    apply_config_patch, fix_issues, get_system_status, get_status_light, list_history, list_recipes,
    list_model_profiles, upsert_model_profile, delete_model_profile,
    list_model_catalog, get_cached_model_catalog, refresh_model_catalog, resolve_provider_auth,
    check_openclaw_update, extract_model_profiles_from_config,
    list_agent_ids, list_agents_overview, create_agent, delete_agent, setup_agent_identity, list_memory_files, delete_memory_file, clear_memory, list_session_files,
    delete_session_file, clear_all_sessions, clear_agent_sessions, analyze_sessions, delete_sessions_by_ids, preview_session,
    preview_rollback, rollback, run_doctor_command,
    resolve_api_keys, read_raw_config, resolve_full_api_key, open_url, chat_via_openclaw,
    backup_before_upgrade, list_backups, restore_from_backup, delete_backup,
    list_channels_minimal,
    list_discord_guild_channels,
    refresh_discord_guild_channels,
    restart_gateway,
    set_global_model,
    set_agent_model,
    list_bindings,
    assign_channel_agent,
    save_config_baseline, check_config_dirty, discard_config_changes, apply_pending_changes,
    list_ssh_hosts, upsert_ssh_host, delete_ssh_host,
    ssh_connect, ssh_disconnect, ssh_status,
    ssh_exec, sftp_read_file, sftp_write_file, sftp_list_dir, sftp_remove_file,
    remote_read_raw_config, remote_get_system_status,
    remote_list_agents_overview, remote_list_channels_minimal, remote_list_bindings,
    remote_restart_gateway, remote_apply_config_patch,
    remote_create_agent, remote_delete_agent,
    remote_assign_channel_agent, remote_set_global_model, remote_set_agent_model,
    remote_run_doctor, remote_list_history, remote_preview_rollback, remote_rollback,
    remote_list_discord_guild_channels, remote_write_raw_config,
    remote_analyze_sessions, remote_delete_sessions_by_ids,
    remote_list_session_files, remote_clear_all_sessions, remote_preview_session,
    remote_list_model_profiles, remote_upsert_model_profile, remote_delete_model_profile, remote_resolve_api_keys,
    remote_extract_model_profiles_from_config, remote_refresh_model_catalog,
    remote_chat_via_openclaw, remote_check_openclaw_update,
    remote_save_config_baseline, remote_check_config_dirty, remote_discard_config_changes, remote_apply_pending_changes,
    run_openclaw_upgrade, remote_run_openclaw_upgrade,
    remote_backup_before_upgrade, remote_list_backups, remote_restore_from_backup, remote_delete_backup,
    RemoteConfigBaselines,
};
use crate::ssh::SshConnectionPool;

pub mod commands;
pub mod config_io;
pub mod doctor;
pub mod history;
pub mod models;
pub mod recipe;
pub mod ssh;

pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_updater::Builder::new().build())
        .plugin(tauri_plugin_process::init())
        .manage(SshConnectionPool::new())
        .manage(RemoteConfigBaselines::new())
        .invoke_handler(tauri::generate_handler![
            get_system_status,
            get_status_light,
            list_recipes,
            list_model_profiles,
            list_model_catalog,
            get_cached_model_catalog,
            refresh_model_catalog,
            upsert_model_profile,
            delete_model_profile,
            resolve_provider_auth,
            list_agent_ids,
            list_agents_overview,
            create_agent,
            delete_agent,
            setup_agent_identity,
            list_memory_files,
            delete_memory_file,
            clear_memory,
            list_session_files,
            delete_session_file,
            clear_all_sessions,
            clear_agent_sessions,
            analyze_sessions,
            delete_sessions_by_ids,
            preview_session,
            check_openclaw_update,
            extract_model_profiles_from_config,
            apply_config_patch,
            list_history,
            preview_rollback,
            rollback,
            run_doctor_command,
            fix_issues,
            resolve_api_keys,
            read_raw_config,
            resolve_full_api_key,
            open_url,
            chat_via_openclaw,
            backup_before_upgrade,
            list_backups,
            restore_from_backup,
            delete_backup,
            list_channels_minimal,
            list_discord_guild_channels,
            refresh_discord_guild_channels,
            restart_gateway,
            set_global_model,
            set_agent_model,
            list_bindings,
            assign_channel_agent,
            save_config_baseline,
            check_config_dirty,
            discard_config_changes,
            apply_pending_changes,
            list_ssh_hosts,
            upsert_ssh_host,
            delete_ssh_host,
            ssh_connect,
            ssh_disconnect,
            ssh_status,
            ssh_exec,
            sftp_read_file,
            sftp_write_file,
            sftp_list_dir,
            sftp_remove_file,
            remote_read_raw_config,
            remote_get_system_status,
            remote_list_agents_overview,
            remote_list_channels_minimal,
            remote_list_bindings,
            remote_restart_gateway,
            remote_apply_config_patch,
            remote_create_agent,
            remote_delete_agent,
            remote_assign_channel_agent,
            remote_set_global_model,
            remote_set_agent_model,
            remote_run_doctor,
            remote_list_history,
            remote_preview_rollback,
            remote_rollback,
            remote_list_discord_guild_channels,
            remote_write_raw_config,
            remote_analyze_sessions,
            remote_delete_sessions_by_ids,
            remote_list_session_files,
            remote_clear_all_sessions,
            remote_preview_session,
            remote_list_model_profiles,
            remote_upsert_model_profile,
            remote_delete_model_profile,
            remote_resolve_api_keys,
            remote_extract_model_profiles_from_config,
            remote_refresh_model_catalog,
            remote_chat_via_openclaw,
            remote_check_openclaw_update,
            remote_save_config_baseline,
            remote_check_config_dirty,
            remote_discard_config_changes,
            remote_apply_pending_changes,
            run_openclaw_upgrade,
            remote_run_openclaw_upgrade,
            remote_backup_before_upgrade,
            remote_list_backups,
            remote_restore_from_backup,
            remote_delete_backup,
        ])
        .run(tauri::generate_context!())
        .expect("failed to run app");
}
