use std::time::Duration;
use async_trait::async_trait;
use crate::backend::{
AdmissionDecision, CancelFlowPolicy, CancelFlowWait, CapabilitySet, ClaimPolicy,
FailOutcome, FailureClass, FailureReason, Frame, Handle, LeaseRenewal, ReclaimToken,
ResumeSignal, WaitpointSpec,
};
use crate::contracts::{CancelFlowResult, ExecutionSnapshot, FlowSnapshot};
use crate::engine_error::EngineError;
use crate::types::{BudgetId, ExecutionId, FlowId, LaneId, TimestampMs};
#[async_trait]
pub trait EngineBackend: Send + Sync + 'static {
async fn claim(
&self,
lane: &LaneId,
capabilities: &CapabilitySet,
policy: ClaimPolicy,
) -> Result<Option<Handle>, EngineError>;
async fn renew(&self, handle: &Handle) -> Result<LeaseRenewal, EngineError>;
async fn progress(
&self,
handle: &Handle,
percent: Option<u8>,
message: Option<String>,
) -> Result<(), EngineError>;
async fn append_frame(&self, handle: &Handle, frame: Frame) -> Result<(), EngineError>;
async fn complete(
&self,
handle: &Handle,
payload: Option<Vec<u8>>,
) -> Result<(), EngineError>;
async fn fail(
&self,
handle: &Handle,
reason: FailureReason,
classification: FailureClass,
) -> Result<FailOutcome, EngineError>;
async fn cancel(&self, handle: &Handle, reason: &str) -> Result<(), EngineError>;
async fn suspend(
&self,
handle: &Handle,
waitpoints: Vec<WaitpointSpec>,
timeout: Option<Duration>,
) -> Result<Handle, EngineError>;
async fn observe_signals(&self, handle: &Handle)
-> Result<Vec<ResumeSignal>, EngineError>;
async fn claim_from_reclaim(
&self,
token: ReclaimToken,
) -> Result<Option<Handle>, EngineError>;
async fn delay(
&self,
handle: &Handle,
delay_until: TimestampMs,
) -> Result<(), EngineError>;
async fn wait_children(&self, handle: &Handle) -> Result<(), EngineError>;
async fn describe_execution(
&self,
id: &ExecutionId,
) -> Result<Option<ExecutionSnapshot>, EngineError>;
async fn describe_flow(
&self,
id: &FlowId,
) -> Result<Option<FlowSnapshot>, EngineError>;
async fn cancel_flow(
&self,
id: &FlowId,
policy: CancelFlowPolicy,
wait: CancelFlowWait,
) -> Result<CancelFlowResult, EngineError>;
async fn report_usage(
&self,
handle: &Handle,
budget: &BudgetId,
dimensions: crate::backend::UsageDimensions,
) -> Result<AdmissionDecision, EngineError>;
}
#[allow(dead_code)]
fn _assert_dyn_compatible(_: &dyn EngineBackend) {}