pub(crate) mod sources;

mod pixmap;

use std::collections::{BTreeMap, HashMap};
use std::fmt::Debug;
use std::sync::Arc;
use tokio::sync::RwLock;
use std::time::SystemTime;
use actix_web::{App, HttpServer};
use actix_web::web::Data;
use wxbox_grib2::GribMessage;

pub struct AppState {
    grib2_cache: RwLock<HashMap<String, Arc<RwLock<GribMessage>>>>,
    grib2_cache_timestamps: RwLock<HashMap<String, SystemTime>>
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    tracing_subscriber::fmt::init();

    let data = Data::new(AppState {
        grib2_cache: RwLock::new(HashMap::new()),
        grib2_cache_timestamps: RwLock::new(HashMap::new())
    });
    HttpServer::new(move || {
        App::new()
            .service(sources::noaa::noaa_mrms_merged_composite_reflectivity_qc)
            .app_data(data.clone())
    })
        .bind(("::", 8080))?
        .run()
        .await

}

