use drasi_lib::reactions::Reaction;
use drasi_plugin_sdk::prelude::*;
use utoipa::OpenApi;
use crate::ApplicationReactionBuilder;
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
#[schema(as = reaction::application::ApplicationReactionConfig)]
#[serde(rename_all = "camelCase")]
pub struct ApplicationReactionConfigDto {}
#[derive(OpenApi)]
#[openapi(components(schemas(ApplicationReactionConfigDto)))]
struct ApplicationReactionSchemas;
pub struct ApplicationReactionDescriptor;
#[async_trait]
impl ReactionPluginDescriptor for ApplicationReactionDescriptor {
fn kind(&self) -> &str {
"application"
}
fn config_version(&self) -> &str {
"1.0.0"
}
fn config_schema_name(&self) -> &str {
"reaction.application.ApplicationReactionConfig"
}
fn config_schema_json(&self) -> String {
let api = ApplicationReactionSchemas::openapi();
serde_json::to_string(
&api.components
.as_ref()
.expect("OpenAPI components missing")
.schemas,
)
.expect("Failed to serialize config schema")
}
async fn create_reaction(
&self,
id: &str,
query_ids: Vec<String>,
_config_json: &serde_json::Value,
auto_start: bool,
) -> anyhow::Result<Box<dyn Reaction>> {
let (reaction, _handle) = ApplicationReactionBuilder::new(id)
.with_queries(query_ids)
.with_auto_start(auto_start)
.build();
Ok(Box::new(reaction))
}
}