use crate::resources::Resource;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LogisticsConfig {
pub global_throughput_multiplier: f32,
pub max_routes_per_update: usize,
pub auto_disable_failed_routes: bool,
pub failure_threshold: u32,
pub enable_spatial_optimization: bool,
pub enable_batch_optimization: bool,
}
impl Default for LogisticsConfig {
fn default() -> Self {
Self {
global_throughput_multiplier: 1.0,
max_routes_per_update: 1000, auto_disable_failed_routes: true,
failure_threshold: 10,
enable_spatial_optimization: false,
enable_batch_optimization: true,
}
}
}
impl LogisticsConfig {
pub fn with_throughput_multiplier(mut self, multiplier: f32) -> Self {
self.global_throughput_multiplier = multiplier;
self
}
pub fn with_max_routes_per_update(mut self, max: usize) -> Self {
self.max_routes_per_update = max;
self
}
pub fn with_failure_threshold(mut self, threshold: u32) -> Self {
self.failure_threshold = threshold;
self
}
pub fn with_auto_disable(mut self, enabled: bool) -> Self {
self.auto_disable_failed_routes = enabled;
self
}
}
impl Resource for LogisticsConfig {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_config() {
let config = LogisticsConfig::default();
assert_eq!(config.global_throughput_multiplier, 1.0);
assert_eq!(config.max_routes_per_update, 1000);
assert!(config.auto_disable_failed_routes);
assert_eq!(config.failure_threshold, 10);
}
#[test]
fn test_config_builder() {
let config = LogisticsConfig::default()
.with_throughput_multiplier(2.0)
.with_max_routes_per_update(500)
.with_failure_threshold(5)
.with_auto_disable(false);
assert_eq!(config.global_throughput_multiplier, 2.0);
assert_eq!(config.max_routes_per_update, 500);
assert_eq!(config.failure_threshold, 5);
assert!(!config.auto_disable_failed_routes);
}
}