use crate::ineru::IneruConfig;
use crate::kaneru::KaneruConfig;
use crate::nested_learning::NestedConfig;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AiConfig {
pub titans: IneruConfig,
pub nested_learning: NestedConfig,
pub kaneru: KaneruConfig,
pub predictive_validation: bool,
pub adaptive_consensus: bool,
pub iot_mode: bool,
}
impl Default for AiConfig {
fn default() -> Self {
Self {
titans: IneruConfig::default(),
nested_learning: NestedConfig::default(),
kaneru: KaneruConfig::default(),
predictive_validation: true,
adaptive_consensus: true,
iot_mode: false,
}
}
}
impl AiConfig {
pub fn iot() -> Self {
Self {
titans: IneruConfig::iot(),
nested_learning: NestedConfig::iot(),
kaneru: KaneruConfig::iot(),
predictive_validation: false, adaptive_consensus: true,
iot_mode: true,
}
}
pub fn full_power() -> Self {
Self {
titans: IneruConfig::full_power(),
nested_learning: NestedConfig::full_power(),
kaneru: KaneruConfig::full_power(),
predictive_validation: true,
adaptive_consensus: true,
iot_mode: false,
}
}
pub fn from_toml(content: &str) -> Result<Self, toml::de::Error> {
toml::from_str(content)
}
pub fn to_toml(&self) -> Result<String, toml::ser::Error> {
toml::to_string_pretty(self)
}
pub fn validate(&self) -> Result<(), String> {
self.titans.validate()?;
self.nested_learning.validate()?;
self.kaneru.validate()?;
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_config() {
let config = AiConfig::default();
assert!(config.validate().is_ok());
}
#[test]
fn test_iot_config() {
let config = AiConfig::iot();
assert!(config.iot_mode);
assert!(!config.predictive_validation);
assert!(config.validate().is_ok());
}
#[test]
fn test_toml_roundtrip() {
let config = AiConfig::default();
let toml = config.to_toml().unwrap();
let parsed = AiConfig::from_toml(&toml).unwrap();
assert_eq!(config.iot_mode, parsed.iot_mode);
}
}