#![allow(clippy::blocks_in_conditions)]

use std::str::FromStr;

#[cfg(feature = "rest")]
use rot::rest;
#[cfg(feature = "rowing-tera")]
use rot::tera;

use sqlx::{pool::PoolOptions, sqlite::SqliteConnectOptions, ConnectOptions};

#[macro_use]
extern crate rocket;

#[launch]
async fn rocket() -> _ {
    use sqlx::SqlitePool;

    env_logger::init();

    let connection_options = SqliteConnectOptions::from_str("sqlite://db.sqlite")
        .unwrap()
        .log_statements(log::LevelFilter::Debug);
    let db: SqlitePool = PoolOptions::new()
        .connect_with(connection_options)
        .await
        .unwrap();

    let rocket = rocket::build().manage(db);

    #[cfg(feature = "rowing-tera")]
    let rocket = tera::config(rocket);

    #[cfg(feature = "rest")]
    let rocket = rest::config(rocket);

    rocket
}
