pub mod config;
pub mod metrics;
pub mod plugin;
pub mod supervisor;

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

pub use config::ProcessConfig;
pub use plugin::ProcessPlugin;

struct ProcessPluginFactory;

impl PluginFactory for ProcessPluginFactory {
    fn create(&self, config: Value) -> Result<Box<dyn Plugin>> {
        let config: ProcessConfig = serde_json::from_value(config)
            .map_err(|e| anyhow!("invalid [process] configuration: {e}"))?;
        Ok(Box::new(ServerPluginWrapper::new(ProcessPlugin::new(
            config,
        ))))
    }
}

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