nodata 0.1.0

nodata is a kafka like message broker that is simple and easy to use, while relying on either local or s3 like data storage for consistency
use std::{ops::Deref, sync::Arc};

use prometheus::Registry;

use crate::services::{consumers::Consumers, handler::Handler, staging::Staging};

#[derive(Clone)]
pub struct SharedState(Arc<State>);

impl SharedState {
    pub async fn new() -> anyhow::Result<Self> {
        Ok(Self(Arc::new(State::new().await?)))
    }
}

impl Deref for SharedState {
    type Target = Arc<State>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

pub struct State {
    pub staging: Staging,
    pub consumers: Consumers,
    pub handler: Handler,
    pub metrics_registry: Registry,
}

impl State {
    pub async fn new() -> anyhow::Result<Self> {
        let staging = Staging::new().await?;
        let handler = Handler::new(staging.clone());

        Ok(Self {
            consumers: Consumers::new(),
            staging,
            handler,
            metrics_registry: Registry::new(),
        })
    }
}