use async_trait::async_trait;
use crate::domain::{
ConversationDump, EngineCapabilities, Mailbox, Message, RoutingDecision, StructuredResult, Task,
};
use crate::error::Result;
#[async_trait]
pub trait EnginePort: Send + Sync {
async fn start(&self, task: &Task) -> Result<crate::domain::Session>;
async fn resume(&self, conv_id: &str, prompt: &str) -> Result<crate::domain::Session>;
async fn dump(&self, conv_id: &str) -> Result<ConversationDump>;
async fn cancel(&self, conv_id: &str) -> Result<()>;
async fn wire_mailbox(&self, conv_id: &str, mailbox: &Mailbox) -> Result<()>;
fn extract_result(&self, dump: &ConversationDump) -> Result<StructuredResult>;
fn capabilities(&self) -> EngineCapabilities;
}
#[async_trait]
pub trait RoutingPort: Send + Sync {
async fn route(&self, task: &Task) -> Result<String> {
Ok(self.route_decision(task).await?.engine)
}
async fn route_decision(&self, task: &Task) -> Result<RoutingDecision>;
}
#[async_trait]
pub trait TransportPort: Send + Sync {
async fn publish(&self, message: &Message) -> Result<()>;
async fn subscribe(&self, owner: &str) -> Result<Vec<Message>>;
async fn claim(&self, owner: &str, message_id: &uuid::Uuid) -> Result<Message>;
async fn mailbox(&self, owner: &str) -> Result<Mailbox>;
}
#[async_trait]
pub trait StorePort: Send + Sync {
async fn persist(&self, task: &Task) -> Result<()>;
async fn load(&self, id: &uuid::Uuid) -> Result<Task>;
async fn persist_result(&self, task_id: &uuid::Uuid, result: &StructuredResult) -> Result<()>;
async fn claim_atomic(&self, id: &uuid::Uuid) -> Result<Task>;
}
#[async_trait]
pub trait DispatchApi: Send + Sync {
async fn dispatch(&self, task: Task) -> Result<StructuredResult>;
async fn get(&self, id: &uuid::Uuid) -> Result<Task>;
async fn cancel(&self, id: &uuid::Uuid) -> Result<()>;
}