Skip to main content

maple_runtime/runtime_core/
profile_manager.rs

1//! Profile Manager - validates and enforces profile constraints
2
3use crate::config::ProfileConfig;
4use crate::runtime_core::ResonatorSpec;
5use crate::types::*;
6
7/// Profile manager validates Resonator specifications against profile rules
8pub struct ProfileManager {
9    config: ProfileConfig,
10}
11
12impl ProfileManager {
13    pub fn new(config: &ProfileConfig) -> Self {
14        Self {
15            config: config.clone(),
16        }
17    }
18
19    /// Validate a Resonator spec against profile constraints
20    pub fn validate_spec(&self, spec: &ResonatorSpec) -> Result<(), String> {
21        // Check if profile is allowed
22        if !self.config.allowed_profiles.contains(&spec.profile) {
23            return Err(format!("Profile {:?} not allowed", spec.profile));
24        }
25
26        // Check human profiles if restricted
27        if !self.config.human_profiles_allowed && spec.profile.requires_agency_protection() {
28            return Err("Human profiles not allowed in this configuration".to_string());
29        }
30
31        // Profile-specific validation
32        match spec.profile {
33            ResonatorProfile::Human => {
34                // Human profiles require extra validation
35                if spec.attention.total_capacity == 0 {
36                    return Err("Human profiles require non-zero attention capacity".to_string());
37                }
38            }
39            ResonatorProfile::IBank => {
40                // IBank profiles have strict requirements
41                if !self.config.allow_ibank_profiles {
42                    return Err("IBank profiles not allowed".to_string());
43                }
44            }
45            _ => {}
46        }
47
48        Ok(())
49    }
50
51    /// Can these two profiles couple?
52    pub fn can_couple(&self, profile_a: &ResonatorProfile, profile_b: &ResonatorProfile) -> bool {
53        profile_a.can_couple_with(profile_b)
54    }
55}