#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

mod db;

use db::commands;
use std::sync::Mutex;

fn main() {
    let db_path = {
        let path = dirs_next::config_dir()
            .unwrap_or_else(|| std::path::PathBuf::from("."))
            .join("com.teloprax.alpha")
            .join("alpha.db");

        std::fs::create_dir_all(path.parent().unwrap()).ok();
        path.to_str().unwrap().to_string()
    };

    tauri::Builder::default()
        .plugin(tauri_plugin_opener::init())
        .plugin(tauri_plugin_http::init())
        .manage(Mutex::new(db_path))
        .invoke_handler(tauri::generate_handler![
            commands::get_projects,
            commands::save_project,
            commands::update_project_counts,
            commands::delete_project,
            commands::get_work_items,
            commands::save_work_item,
            commands::delete_work_item,
            commands::get_users,
            commands::save_user,
            commands::update_user_fields,
            commands::get_cells,
            commands::save_cell,
            commands::save_project_members,
            commands::get_project_members,
            commands::get_absences,
            commands::save_absence,
            commands::delete_absence,
            commands::get_daily_logs,
            commands::save_daily_log,
            commands::get_performance,
            commands::save_performance,
            commands::get_epics,
            commands::save_epic,
            commands::delete_epic,
            commands::get_user_stories,
            commands::save_user_story,
            commands::delete_user_story,
            commands::get_impairments,
            commands::save_impairment,
            commands::delete_impairment,
            commands::get_hu_drafts,
            commands::save_hu_draft,
            commands::delete_hu_draft,
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
