1use serde::{Deserialize, Serialize};
4use std::time::Duration;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct CloudCostMonitoringConfig {
9 pub enabled: bool,
11 pub granularity: CostTrackingGranularity,
13 pub budget_tracking: BudgetTrackingConfig,
15 pub optimization_tracking: CostOptimizationTrackingConfig,
17 pub allocation: CostAllocationConfig,
19 pub billing: BillingIntegrationConfig,
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
25pub enum CostTrackingGranularity {
26 PerHour,
27 PerDay,
28 PerWeek,
29 PerMonth,
30 PerProject,
31 PerDepartment,
32 PerUser,
33 PerResource,
34 Custom(String),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct BudgetTrackingConfig {
40 pub track_utilization: bool,
42 pub track_variance: bool,
44 pub forecast_consumption: bool,
46 pub alert_thresholds: Vec<f64>,
48 pub budget_periods: Vec<BudgetPeriod>,
50 pub multi_level: MultilevelBudgetConfig,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
56pub struct BudgetPeriod {
57 pub name: String,
59 pub duration: Duration,
61 pub amount: f64,
63 pub currency: String,
65 pub rollover_policy: RolloverPolicy,
67}
68
69#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
71pub enum RolloverPolicy {
72 NoRollover,
73 FullRollover,
74 PartialRollover(f64), Custom(String),
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct MultilevelBudgetConfig {
81 pub enabled: bool,
83 pub levels: Vec<BudgetLevel>,
85 pub allocation_strategies: Vec<AllocationStrategy>,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct BudgetLevel {
92 pub name: String,
94 pub parent: Option<String>,
96 pub amount: f64,
98 pub allocation_rules: Vec<AllocationRule>,
100}
101
102#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
104pub enum AllocationStrategy {
105 EqualDistribution,
106 WeightedDistribution,
107 UsageBased,
108 PriorityBased,
109 Custom(String),
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct AllocationRule {
115 pub name: String,
117 pub targets: Vec<String>,
119 pub percentage: f64,
121 pub conditions: Vec<AllocationCondition>,
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize)]
127pub struct AllocationCondition {
128 pub condition_type: ConditionType,
130 pub value: String,
132 pub operator: ComparisonOperator,
134}
135
136#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
138pub enum ConditionType {
139 ResourceType,
140 Department,
141 Project,
142 User,
143 Tag,
144 Custom(String),
145}
146
147#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
149pub enum ComparisonOperator {
150 Equals,
151 NotEquals,
152 Contains,
153 StartsWith,
154 EndsWith,
155 GreaterThan,
156 LessThan,
157 In(Vec<String>),
158}
159
160#[derive(Debug, Clone, Serialize, Deserialize)]
162pub struct CostOptimizationTrackingConfig {
163 pub track_opportunities: bool,
165 pub track_implementations: bool,
167 pub roi_tracking: ROITrackingConfig,
169 pub recommendations: OptimizationRecommendationConfig,
171}
172
173#[derive(Debug, Clone, Serialize, Deserialize)]
175pub struct ROITrackingConfig {
176 pub calculate_roi: bool,
178 pub calculation_period: Duration,
180 pub include_indirect_benefits: bool,
182 pub metrics: Vec<ROIMetric>,
184}
185
186#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
188pub enum ROIMetric {
189 CostSavings,
190 ProductivityGains,
191 QualityImprovements,
192 RiskReduction,
193 TimeToMarket,
194 Custom(String),
195}
196
197#[derive(Debug, Clone, Serialize, Deserialize)]
199pub struct OptimizationRecommendationConfig {
200 pub enabled: bool,
202 pub types: Vec<RecommendationType>,
204 pub frequency: Duration,
206 pub savings_threshold: f64,
208}
209
210#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
212pub enum RecommendationType {
213 RightSizing,
214 ReservedInstances,
215 SpotInstances,
216 ScheduledShutdown,
217 StorageOptimization,
218 NetworkOptimization,
219 QuantumCircuitOptimization,
220 Custom(String),
221}
222
223#[derive(Debug, Clone, Serialize, Deserialize)]
225pub struct CostAllocationConfig {
226 pub enabled: bool,
228 pub methods: Vec<CostAllocationMethod>,
230 pub tag_based: TagBasedAllocationConfig,
232 pub usage_based: UsageBasedAllocationConfig,
234}
235
236#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
238pub enum CostAllocationMethod {
239 Direct,
240 Proportional,
241 ActivityBased,
242 TagBased,
243 UsageBased,
244 Custom(String),
245}
246
247#[derive(Debug, Clone, Serialize, Deserialize)]
249pub struct TagBasedAllocationConfig {
250 pub primary_tags: Vec<String>,
252 pub secondary_tags: Vec<String>,
254 pub default_allocation: String,
256}
257
258#[derive(Debug, Clone, Serialize, Deserialize)]
260pub struct UsageBasedAllocationConfig {
261 pub metrics: Vec<AllocationMetric>,
263 pub weights: std::collections::HashMap<AllocationMetric, f64>,
265 pub frequency: Duration,
267}
268
269#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
271pub enum AllocationMetric {
272 CPUHours,
273 MemoryHours,
274 StorageGB,
275 NetworkGBTransferred,
276 QuantumCircuitExecutions,
277 DatabaseQueries,
278 Custom(String),
279}
280
281#[derive(Debug, Clone, Serialize, Deserialize)]
283pub struct BillingIntegrationConfig {
284 pub enabled: bool,
286 pub providers: Vec<BillingProvider>,
288 pub frequency: BillingFrequency,
290 pub cost_center_mapping: CostCenterMappingConfig,
292}
293
294#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
296pub enum BillingProvider {
297 AWS,
298 Azure,
299 GCP,
300 Custom(String),
301}
302
303#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
305pub enum BillingFrequency {
306 RealTime,
307 Hourly,
308 Daily,
309 Weekly,
310 Monthly,
311 Custom(Duration),
312}
313
314#[derive(Debug, Clone, Serialize, Deserialize)]
316pub struct CostCenterMappingConfig {
317 pub rules: Vec<CostCenterRule>,
319 pub default_cost_center: String,
321 pub validation: CostCenterValidationConfig,
323}
324
325#[derive(Debug, Clone, Serialize, Deserialize)]
327pub struct CostCenterRule {
328 pub name: String,
330 pub conditions: Vec<AllocationCondition>,
332 pub target_cost_center: String,
334 pub priority: i32,
336}
337
338#[derive(Debug, Clone, Serialize, Deserialize)]
340pub struct CostCenterValidationConfig {
341 pub require_valid: bool,
343 pub valid_centers: Vec<String>,
345 pub validation_frequency: Duration,
347}
348
349impl Default for CloudCostMonitoringConfig {
350 fn default() -> Self {
351 Self {
352 enabled: true,
353 granularity: CostTrackingGranularity::PerDay,
354 budget_tracking: BudgetTrackingConfig::default(),
355 optimization_tracking: CostOptimizationTrackingConfig::default(),
356 allocation: CostAllocationConfig::default(),
357 billing: BillingIntegrationConfig::default(),
358 }
359 }
360}
361
362impl Default for BudgetTrackingConfig {
363 fn default() -> Self {
364 Self {
365 track_utilization: true,
366 track_variance: true,
367 forecast_consumption: false,
368 alert_thresholds: vec![50.0, 75.0, 90.0, 100.0],
369 budget_periods: vec![],
370 multi_level: MultilevelBudgetConfig::default(),
371 }
372 }
373}
374
375impl Default for MultilevelBudgetConfig {
376 fn default() -> Self {
377 Self {
378 enabled: false,
379 levels: vec![],
380 allocation_strategies: vec![AllocationStrategy::EqualDistribution],
381 }
382 }
383}
384
385impl Default for CostOptimizationTrackingConfig {
386 fn default() -> Self {
387 Self {
388 track_opportunities: true,
389 track_implementations: false,
390 roi_tracking: ROITrackingConfig::default(),
391 recommendations: OptimizationRecommendationConfig::default(),
392 }
393 }
394}
395
396impl Default for ROITrackingConfig {
397 fn default() -> Self {
398 Self {
399 calculate_roi: false,
400 calculation_period: Duration::from_secs(86400 * 30), include_indirect_benefits: false,
402 metrics: vec![ROIMetric::CostSavings],
403 }
404 }
405}
406
407impl Default for OptimizationRecommendationConfig {
408 fn default() -> Self {
409 Self {
410 enabled: false,
411 types: vec![RecommendationType::RightSizing],
412 frequency: Duration::from_secs(86400 * 7), savings_threshold: 100.0, }
415 }
416}
417
418impl Default for CostAllocationConfig {
419 fn default() -> Self {
420 Self {
421 enabled: false,
422 methods: vec![CostAllocationMethod::TagBased],
423 tag_based: TagBasedAllocationConfig::default(),
424 usage_based: UsageBasedAllocationConfig::default(),
425 }
426 }
427}
428
429impl Default for TagBasedAllocationConfig {
430 fn default() -> Self {
431 Self {
432 primary_tags: vec!["Project".to_string(), "Department".to_string()],
433 secondary_tags: vec!["Environment".to_string()],
434 default_allocation: "Unallocated".to_string(),
435 }
436 }
437}
438
439impl Default for UsageBasedAllocationConfig {
440 fn default() -> Self {
441 let mut weights = std::collections::HashMap::new();
442 weights.insert(AllocationMetric::CPUHours, 0.4);
443 weights.insert(AllocationMetric::MemoryHours, 0.3);
444 weights.insert(AllocationMetric::StorageGB, 0.2);
445 weights.insert(AllocationMetric::NetworkGBTransferred, 0.1);
446
447 Self {
448 metrics: vec![
449 AllocationMetric::CPUHours,
450 AllocationMetric::MemoryHours,
451 AllocationMetric::StorageGB,
452 ],
453 weights,
454 frequency: Duration::from_secs(3600), }
456 }
457}
458
459impl Default for BillingIntegrationConfig {
460 fn default() -> Self {
461 Self {
462 enabled: false,
463 providers: vec![],
464 frequency: BillingFrequency::Daily,
465 cost_center_mapping: CostCenterMappingConfig::default(),
466 }
467 }
468}
469
470impl Default for CostCenterMappingConfig {
471 fn default() -> Self {
472 Self {
473 rules: vec![],
474 default_cost_center: "Default".to_string(),
475 validation: CostCenterValidationConfig::default(),
476 }
477 }
478}
479
480impl Default for CostCenterValidationConfig {
481 fn default() -> Self {
482 Self {
483 require_valid: false,
484 valid_centers: vec![],
485 validation_frequency: Duration::from_secs(86400), }
487 }
488}