use crate::database::Database;
use crate::merger::Merger;
use crate::queryer::Queryer;
use crate::validator::Validator;
use std::sync::Arc;

pub struct Jspg {
  pub database: Arc<Database>,
  pub validator: Validator,
  pub queryer: Queryer,
  pub merger: Merger,
}

impl Jspg {
  pub fn new(database_val: &serde_json::Value) -> Result<Self, crate::drop::Drop> {
    let database_instance = Database::new(database_val)?;
    let database = Arc::new(database_instance);
    let validator = Validator::new(database.clone());
    let queryer = Queryer::new(database.clone());
    let merger = Merger::new(database.clone());

    Ok(Self {
      database,
      validator,
      queryer,
      merger,
    })
  }
}
