pub mod config;
pub mod driver;
pub mod plugin;
pub mod redis_driver;

use anyhow::Result;
use folk_api::{Plugin, PluginFactory, ServerPluginWrapper};
use serde_json::Value;

pub use config::JobsConfig;
pub use driver::{Driver, MemoryDriver};
pub use plugin::JobsPlugin;
pub use redis_driver::RedisDriver;

struct JobsPluginFactory;

impl PluginFactory for JobsPluginFactory {
    fn create(&self, config: Value) -> Result<Box<dyn Plugin>> {
        let config: JobsConfig = serde_json::from_value(config)?;
        Ok(Box::new(ServerPluginWrapper::new(JobsPlugin::new(config))))
    }
}

pub fn folk_plugin_factory() -> Box<dyn PluginFactory> {
    Box::new(JobsPluginFactory)
}
