use super::types::*;
use async_trait::async_trait;
#[async_trait]
pub trait LogisticsHook: Send + Sync {
async fn on_transfer_complete(&self, _route_id: &RouteId, _item_id: &ItemId, _amount: u32) {
}
async fn on_transfer_failed(&self, _route_id: &RouteId, _reason: String) {
}
async fn on_route_disabled(&self, _route_id: &RouteId, _reason: &str) {
}
async fn calculate_transport_cost(&self, _item_id: &ItemId, amount: u32, distance: f32) -> f32 {
amount as f32 * distance * 0.1
}
}
pub struct DefaultLogisticsHook;
#[async_trait]
impl LogisticsHook for DefaultLogisticsHook {}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_default_hook() {
let hook = DefaultLogisticsHook;
hook.on_transfer_complete(&"route1".into(), &"iron".into(), 10)
.await;
hook.on_transfer_failed(&"route1".into(), "test error".into())
.await;
hook.on_route_disabled(&"route1".into(), "test reason")
.await;
let cost = hook.calculate_transport_cost(&"iron".into(), 10, 5.0).await;
assert_eq!(cost, 5.0);
}
}