use std::sync::Arc;
use serde::de::DeserializeOwned;
use serde::Serialize;
use wick_interface_types::{ComponentSignature, OperationSignature};
use wick_packet::{ComponentReference, InherentData, Invocation, PacketStream, RuntimeConfig};
use crate::context::Context;
use crate::{BoxFuture, ComponentError};
pub type SharedComponent = Arc<dyn Component + Send + Sync>;
pub trait Component {
fn handle(
&self,
invocation: Invocation,
data: Option<RuntimeConfig>,
callback: crate::LocalScope,
) -> BoxFuture<Result<PacketStream, anyhow::Error>>;
fn signature(&self) -> &ComponentSignature;
fn shutdown(&self) -> BoxFuture<Result<(), anyhow::Error>> {
Box::pin(async move { Ok(()) })
}
}
pub trait RenderConfiguration {
type Config: std::fmt::Debug + DeserializeOwned + Serialize + Send + Sync + 'static;
type ConfigSource: std::fmt::Debug;
fn decode_config(data: Option<Self::ConfigSource>) -> Result<Self::Config, ComponentError>;
}
pub trait Operation {
const ID: &'static str;
type Config: std::fmt::Debug + DeserializeOwned + Serialize + Send + Sync + 'static;
fn handle(
&self,
invocation: Invocation,
context: Context<Self::Config>,
) -> BoxFuture<Result<PacketStream, ComponentError>>;
fn get_signature(&self, config: Option<&Self::Config>) -> &OperationSignature;
fn input_names(&self, config: &Self::Config) -> Vec<String>;
}
pub type ScopeInvokeFn = dyn Fn(
ComponentReference,
String,
PacketStream,
InherentData,
Option<RuntimeConfig>,
&tracing::Span,
) -> BoxFuture<'static, Result<PacketStream, ComponentError>>
+ Send
+ Sync;