pub mod config;
pub mod state;

use crate::initializers;
use rocket::Build;
use rocket::Rocket;

pub fn run() {
    let rocket = configure_rocket(rocket::build());

    run_rocket(rocket).unwrap_or_else(|e| eprintln!("Hagrid Error: {e}"))
}

pub fn configure_rocket(rocket: Rocket<Build>) -> Rocket<Build> {
    let config = config::load(rocket.figment());

    initializers::run(rocket, &config).expect("Initializers error")
}

pub fn run_rocket(rocket: Rocket<Build>) -> Result<(), rocket::Error> {
    ::rocket::async_main(async move {
        let _rocket = rocket.ignite().await?.launch().await?;

        Ok(())
    })
}
