1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct EnvironmentMedium {
9 pub environment_type: EnvironmentType,
10 pub current_state: EnvironmentState,
11 pub properties: EnvironmentProperties,
12 pub physics: EnvironmentPhysics,
13 pub inhabitants: Vec<String>,
14 pub boundaries: Vec<String>,
15 pub weather_history: Vec<WeatherEvent>,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20pub enum EnvironmentType {
21 Production {
22 tier: String,
23 region: String,
24 criticality: f64,
25 },
26 Staging {
27 mirrors_production: bool,
28 data_freshness: String,
29 },
30 Development {
31 developer: String,
32 local: bool,
33 },
34 Testing {
35 test_type: String,
36 isolation: bool,
37 },
38 Pipeline {
39 pipeline_id: String,
40 stage: String,
41 },
42 Sandbox {
43 owner: String,
44 expires: Option<i64>,
45 },
46 Simulation {
47 fidelity: String,
48 purpose: String,
49 },
50 Preview {
51 traffic_percentage: f64,
52 rollback_ready: bool,
53 },
54 DisasterRecovery {
55 is_active_failover: bool,
56 primary_region: String,
57 },
58 Unknown {
59 clues: Vec<String>,
60 },
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct EnvironmentState {
66 pub health: EnvironmentHealth,
67 pub pressure: EnvironmentPressure,
68 pub stability: StabilityAssessment,
69 pub incidents: Vec<ActiveIncident>,
70 pub degradations: Vec<String>,
71 pub mood: EnvironmentMood,
72 pub last_sensed: i64,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct EnvironmentHealth {
77 pub score: f64,
78 pub components: HashMap<String, f64>,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct EnvironmentPressure {
83 pub level: f64,
84 pub source: String,
85 pub trend: PressureTrend,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub enum PressureTrend {
90 Rising,
91 Stable,
92 Falling,
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize)]
96pub struct StabilityAssessment {
97 pub score: f64,
98 pub window_secs: u64,
99 pub volatility: f64,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
103pub struct ActiveIncident {
104 pub id: String,
105 pub severity: String,
106 pub summary: String,
107 pub started_at: i64,
108 pub acknowledged: bool,
109}
110
111#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
113pub enum EnvironmentMood {
114 Calm,
115 Busy,
116 Stressed,
117 Troubled,
118 Crisis,
119 Recovering,
120 Maintenance,
121 Dying,
122}
123
124impl std::fmt::Display for EnvironmentMood {
125 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
126 match self {
127 Self::Calm => write!(f, "calm"),
128 Self::Busy => write!(f, "busy"),
129 Self::Stressed => write!(f, "stressed"),
130 Self::Troubled => write!(f, "troubled"),
131 Self::Crisis => write!(f, "crisis"),
132 Self::Recovering => write!(f, "recovering"),
133 Self::Maintenance => write!(f, "maintenance"),
134 Self::Dying => write!(f, "dying"),
135 }
136 }
137}
138
139#[derive(Debug, Clone, Serialize, Deserialize)]
141pub struct EnvironmentProperties {
142 pub name: String,
143 pub version: Option<String>,
144 pub config: HashMap<String, String>,
145 pub labels: HashMap<String, String>,
146}
147
148#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct EnvironmentPhysics {
151 pub rate_limits: Vec<RateLimit>,
152 pub cost_constraints: Vec<CostConstraint>,
153 pub time_constraints: Vec<TimeConstraint>,
154 pub quotas: Vec<Quota>,
155 pub permissions: Vec<String>,
156 pub forbidden_actions: Vec<String>,
157 pub compliance: Vec<String>,
158}
159
160#[derive(Debug, Clone, Serialize, Deserialize)]
161pub struct RateLimit {
162 pub resource: String,
163 pub limit: u64,
164 pub window_secs: u64,
165 pub current: u64,
166}
167
168#[derive(Debug, Clone, Serialize, Deserialize)]
169pub struct CostConstraint {
170 pub resource: String,
171 pub budget: f64,
172 pub spent: f64,
173 pub currency: String,
174}
175
176#[derive(Debug, Clone, Serialize, Deserialize)]
177pub struct TimeConstraint {
178 pub name: String,
179 pub deadline: Option<i64>,
180 pub budget_secs: Option<u64>,
181}
182
183#[derive(Debug, Clone, Serialize, Deserialize)]
184pub struct Quota {
185 pub resource: String,
186 pub limit: u64,
187 pub used: u64,
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize)]
192pub struct WeatherEvent {
193 pub event_type: String,
194 pub severity: f64,
195 pub timestamp: i64,
196 pub duration_secs: Option<u64>,
197 pub description: String,
198}
199
200#[derive(Debug, Clone, Serialize, Deserialize)]
202pub struct ContextFingerprint {
203 pub hash: [u8; 32],
204 pub components: ContextComponents,
205 pub captured_at: i64,
206 pub stability: ContextStability,
207 pub similarities: Vec<FingerprintSimilarity>,
208}
209
210#[derive(Debug, Clone, Serialize, Deserialize)]
212pub struct ContextComponents {
213 pub deployment_hash: [u8; 8],
214 pub version_hash: [u8; 8],
215 pub environment_hash: [u8; 8],
216 pub config_hash: [u8; 8],
217 pub resource_hash: [u8; 8],
218 pub capability_hash: [u8; 8],
219 pub temporal_hash: [u8; 8],
220 pub load_hash: [u8; 8],
221 pub network_hash: [u8; 8],
222 pub dependency_hash: [u8; 8],
223}
224
225#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
226pub enum ContextStability {
227 Stable,
228 Drifting,
229 Shifting,
230 Volatile,
231}
232
233#[derive(Debug, Clone, Serialize, Deserialize)]
234pub struct FingerprintSimilarity {
235 pub context_id: String,
236 pub similarity: f64,
237 pub common_components: Vec<String>,
238}