use std::net::SocketAddr;
use axum::{
    routing::{get, get_service}, Router
};
use tower_http::services::ServeDir;

mod error_handling;
mod routes;

use error_handling::AppError;
use routes::{about, contact, index, fontsample};

#[tokio::main]
async fn main() {
    // initialize tracing
    tracing_subscriber::fmt::init();

    // build our application with some routes
    let app = Router::new()
        .nest_service("/assets", ServeDir::new("templates/assets")
            .fallback(get_service(ServeDir::new("templates/assets"))))
        .route("/", get(index))
        .route("/fontsample", get(fontsample))
        .route("/about", get(about))
        .route("/contactus", get(contact))
        ;

    // Send email indicating server has started
    //let recipients = get_useremails_by_role("admin".to_string(), &app_state.db_pool).await;
    //send_emails("Server started".to_string(), recipients, "Server has been started".to_string());

    // run it
    let addr = SocketAddr::from(([0, 0, 0, 0], 40192));
    tracing::debug!("listening on {}", addr);
    axum_server::bind(addr)
        .serve(app.into_make_service())
        .await
        .unwrap();

}
