use crate::app::config::Configuration;
use hagrid_database::Sqlite;
use rocket::Build;
use rocket::Rocket;

pub fn init(config: &Configuration) -> super::Result<Sqlite> {
    let keys_internal_dir = config.keys_internal_dir.as_path();

    Sqlite::new_file(
        Sqlite::db_file_path(keys_internal_dir),
        Sqlite::log_dir_path(keys_internal_dir),
    )
    .map(Some)
}

pub fn register(rocket: Rocket<Build>, _config: &Configuration, state: Sqlite) -> Rocket<Build> {
    rocket.manage(state)
}
