mod util;
mod endpoints;
mod models;
mod repository;

use rocket::{routes};
use util::constants;
use util::debug;
use repository::remote::redis;


 #[rocket::main]
 async fn main() -> Result<(), rocket::Error> {
    util::colored_text::print_colored_text_brand("> SocioCybereeng ");
    util::colored_text::print_colored_text_project("> Project: Hydroponic Systems ");
    util::colored_text::print_colored_text_info("- [Welcome to ResourceHUB API] ");
    
    if util::constants::IS_DEBUG == true {
        debug::print_debug_info();
    }

    // Get database pool
    // let pool = redis::get_pool(constants::DB_URI).await;


    // Attempt to connect to DB and check the result
        // Ok(conection) => {
            // If the connection is successful, store it or use it as needed
            // let mut _db = conection;
    // }


    // Start server
    let _rocket = rocket::build()
        .mount(format!("/api/v{}/", constants::API_VERSION), routes![
            endpoints::sensors::data::create,
            endpoints::sensors::data::get,
            // endpoints::sensors::data::get_by_id,
        ])
        .launch()
        .await?;

    Ok(())
        // },
        // Err(err) => {
        //     // Handle connection error and stop execution
        //     std::process::exit(1);
        // }
    // }
    
 }
