mod config;
mod plugin;
mod service;

pub use config::GrpcConfig;
pub use plugin::GrpcPlugin;
pub use service::GrpcEnvelope;

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

struct GrpcPluginFactory;

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

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