use std::{future::Future, pin::Pin};
use bytes::Bytes;
use rustack_logs_model::{error::LogsError, operations::LogsOperation};
use crate::body::LogsResponseBody;
pub trait LogsHandler: Send + Sync + 'static {
fn handle_operation(
&self,
op: LogsOperation,
body: Bytes,
) -> Pin<Box<dyn Future<Output = Result<http::Response<LogsResponseBody>, LogsError>> + Send>>;
}
pub async fn dispatch_operation<H: LogsHandler>(
handler: &H,
op: LogsOperation,
body: Bytes,
) -> Result<http::Response<LogsResponseBody>, LogsError> {
tracing::debug!(operation = %op, "dispatching CloudWatch Logs operation");
handler.handle_operation(op, body).await
}
#[derive(Debug, Clone, Default)]
pub struct NotImplementedHandler;
impl LogsHandler for NotImplementedHandler {
fn handle_operation(
&self,
op: LogsOperation,
_body: Bytes,
) -> Pin<Box<dyn Future<Output = Result<http::Response<LogsResponseBody>, LogsError>> + Send>>
{
Box::pin(async move { Err(LogsError::not_implemented(op.as_str())) })
}
}