pub mod common;

use std::collections::HashMap;
use oiseau::postgres::{DataManager as OiseauManager, Result};
use crate::config::Config;
use buckets_core::{DataManager as BucketsManager, Config as BucketsConfig};

#[derive(Clone)]
pub struct DataManager(pub OiseauManager<Config>, pub BucketsManager);

impl DataManager {
    /// Create a new [`DataManager`].
    pub async fn new(config: Config) -> Result<Self> {
        let buckets_manager = BucketsManager::new(BucketsConfig {
            directory: format!("{}/{}", config.dirs.media, "uploads"),
            bucket_defaults: HashMap::new(),
            database: config.database.clone(),
            banned_hosts: config.banned_hosts.clone(),
        })
        .await
        .expect("failed to create buckets manager");

        Ok(Self(OiseauManager::new(config).await?, buckets_manager))
    }
}
