mod commands;
mod python_executor;
mod macros;
mod command_utils;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
  tauri::Builder::default()
    .plugin(tauri_plugin_fs::init())
    .plugin(tauri_plugin_dialog::init())
    .plugin(tauri_plugin_shell::init())
    .plugin(tauri_plugin_dialog::init())
    .plugin(tauri_plugin_fs::init())
    .setup(|app| {
      if cfg!(debug_assertions) {
        app.handle().plugin(
          tauri_plugin_log::Builder::default()
            .level(log::LevelFilter::Warn) // Reduce log level to reduce noise
            .filter(|metadata| {
              // Filter out tao event loop warnings
              !metadata.target().contains("tao::platform_impl::platform::event_loop")
            })
            .build(),
        )?;
      }
      Ok(())
    })
    .invoke_handler(tauri::generate_handler![
      commands::greet,
      commands::process_video,
      commands::analyze_audio,
      commands::get_project_info,
      commands::save_project,
      commands::load_project,
      commands::generate_ai_video,
      commands::batch_generate_ai_videos,
      commands::test_ai_video_environment,
      commands::select_image_file,
      commands::select_folder,
      commands::open_folder,
      commands::batch_import_templates,
      commands::batch_import_templates_with_progress,
      commands::get_templates,
      commands::get_template,
      commands::get_template_detail,
      commands::delete_template,
      commands::get_all_resource_categories,
      commands::get_resource_category_by_id,
      commands::create_resource_category,
      commands::update_resource_category,
      commands::delete_resource_category,
      commands::search_resource_categories,
      commands::get_all_projects,
      commands::get_project_by_id,
      commands::create_project,
      commands::update_project,
      commands::delete_project,
      commands::search_projects,
      commands::open_project_directory,
      commands::project::scan_directory,
      commands::project::open_file_in_system,
      commands::project::delete_file,
      commands::model::get_all_models,
      commands::model::get_model_by_id,
      commands::model::create_model,
      commands::model::update_model,
      commands::model::delete_model,
      commands::model::search_models,
      commands::audio::get_all_audio_files,
      commands::audio::get_audio_by_id,
      commands::audio::get_audio_by_md5,
      commands::audio::upload_audio_file,
      commands::audio::batch_upload_audio_files,
      commands::audio::delete_audio_file,
      commands::audio::search_audio_files,
      commands::media::get_all_segments,
      commands::media::get_all_original_videos,
      commands::media::get_segments_by_video_id,
      commands::media::upload_video_file,
      commands::media::batch_upload_video_files,
      commands::media::add_segment_tags,
      commands::media::remove_segment_tags,
      commands::media::increment_segment_usage,
      commands::media::get_segments_by_tags,
      commands::media::get_popular_segments,
      commands::media::search_segments,
      commands::media::delete_segment,
      commands::media::delete_original_video,
      commands::file_utils::read_image_as_data_url,
      commands::file_utils::read_video_as_data_url,
      commands::file_utils::get_video_blob_url,
      commands::file_utils::check_file_exists,
      commands::file_utils::get_file_info,
      // Python Core Demo Commands
      commands::python_core_demo::test_python_core_basic,
      commands::python_core_demo::test_template_manager,
      commands::python_core_demo::test_project_manager,
      commands::python_core_demo::test_file_manager,
      commands::python_core_demo::test_ai_video,
      commands::python_core_demo::test_batch_import_templates,
      commands::python_core_demo::test_create_project,
      commands::python_core_demo::test_get_categories,
      commands::python_core_demo::test_all_python_core_functions,
      // Python Environment Manager Commands
      commands::python_env_manager::get_python_env_status,
      commands::python_env_manager::install_python_package,
      commands::python_env_manager::uninstall_python_package,
      commands::python_env_manager::upgrade_python_package,
      commands::python_env_manager::setup_embedded_python,
      commands::python_env_manager::setup_embedded_python_simple,
      // Mix Edit Commands
      commands::mix_edit::start_mix_edit
    ])
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}
