omni_orchestrator/schemas/v1/models/
cost.rs

1use serde::{Deserialize, Serialize};
2use chrono::{DateTime, Utc};
3use sqlx::{Row, FromRow};
4
5/// Represents a cost metric entry in the system.
6#[derive(Debug, FromRow, Serialize, Deserialize, Clone)]
7pub struct CostMetric {
8    /// Unique identifier
9    pub id: i64,
10    /// Resource type ID
11    pub resource_type_id: i32,
12    /// Provider ID
13    pub provider_id: Option<i64>,
14    /// Region ID
15    pub region_id: Option<i64>,
16    /// Application ID
17    pub app_id: Option<i64>,
18    /// Worker ID
19    pub worker_id: Option<i64>,
20    /// Organization ID
21    pub org_id: Option<i64>,
22    /// Start time of the usage period
23    pub start_time: DateTime<Utc>,
24    /// End time of the usage period
25    pub end_time: DateTime<Utc>,
26    /// Amount of resource used
27    pub usage_quantity: f64,
28    /// Cost per unit
29    pub unit_cost: f64,
30    /// Currency code (e.g., 'USD')
31    pub currency: String,
32    /// Total cost for this usage
33    pub total_cost: f64,
34    /// Discount percentage applied
35    pub discount_percentage: Option<f64>,
36    /// Reason for the discount
37    pub discount_reason: Option<String>,
38    /// Billing period (e.g., '2025-05')
39    pub billing_period: Option<String>,
40    /// Creation timestamp
41    pub created_at: DateTime<Utc>,
42    /// Last update timestamp
43    pub updated_at: DateTime<Utc>,
44}
45
46/// Represents a cost metric with its associated resource type information.
47#[derive(Debug, FromRow, Serialize, Deserialize, Clone)]
48pub struct CostMetricWithType {
49    /// Unique identifier
50    pub id: i64,
51    /// Resource type ID
52    pub resource_type_id: i32,
53    /// Provider ID
54    pub provider_id: Option<i64>,
55    /// Region ID
56    pub region_id: Option<i64>,
57    /// Application ID
58    pub app_id: Option<i64>,
59    /// Worker ID
60    pub worker_id: Option<i64>,
61    /// Organization ID
62    pub org_id: Option<i64>,
63    /// Start time of the usage period
64    pub start_time: DateTime<Utc>,
65    /// End time of the usage period
66    pub end_time: DateTime<Utc>,
67    /// Amount of resource used
68    pub usage_quantity: f64,
69    /// Cost per unit
70    pub unit_cost: f64,
71    /// Currency code (e.g., 'USD')
72    pub currency: String,
73    /// Total cost for this usage
74    pub total_cost: f64,
75    /// Discount percentage applied
76    pub discount_percentage: Option<f64>,
77    /// Reason for the discount
78    pub discount_reason: Option<String>,
79    /// Billing period (e.g., '2025-05')
80    pub billing_period: Option<String>,
81    /// Creation timestamp
82    pub created_at: DateTime<Utc>,
83    /// Last update timestamp
84    pub updated_at: DateTime<Utc>,
85    /// Resource type name
86    pub resource_type_name: String,
87    /// Resource type category
88    pub resource_type_category: String,
89    /// Unit of measurement
90    pub unit_of_measurement: String,
91}
92
93/// Represents a cost budget entry in the system.
94#[derive(Debug, FromRow, Serialize, Deserialize, Clone)]
95pub struct CostBudget {
96    /// Unique identifier
97    pub id: i64,
98    /// Organization ID
99    pub org_id: i64,
100    /// Application ID (optional)
101    pub app_id: Option<i64>,
102    /// Budget name
103    pub budget_name: String,
104    /// Budget amount
105    pub budget_amount: f64,
106    /// Currency code (e.g., 'USD')
107    pub currency: String,
108    /// Budget period type
109    pub budget_period: String,
110    /// Start date of the budget period
111    pub period_start: DateTime<Utc>,
112    /// End date of the budget period
113    pub period_end: DateTime<Utc>,
114    /// Alert threshold percentage
115    pub alert_threshold_percentage: f64,
116    /// Contacts to alert when threshold is reached (JSON)
117    pub alert_contacts: String,
118    /// Whether the budget is active
119    pub is_active: bool,
120    /// Creation timestamp
121    pub created_at: DateTime<Utc>,
122    /// Last update timestamp
123    pub updated_at: DateTime<Utc>,
124    /// User ID who created the budget
125    pub created_by: i64,
126}
127
128/// Represents a cost projection entry in the system.
129#[derive(Debug, FromRow, Serialize, Deserialize, Clone)]
130pub struct CostProjection {
131    /// Unique identifier
132    pub id: i64,
133    /// Organization ID
134    pub org_id: i64,
135    /// Application ID (optional)
136    pub app_id: Option<i64>,
137    /// Projection period type (e.g., 'monthly', 'quarterly')
138    pub projection_period: String,
139    /// Start date of the projection period
140    pub start_date: DateTime<Utc>,
141    /// End date of the projection period
142    pub end_date: DateTime<Utc>,
143    /// Projected cost amount
144    pub projected_cost: f64,
145    /// Currency code (e.g., 'USD')
146    pub currency: String,
147    /// Projection model used (e.g., 'linear', 'average_30d')
148    pub projection_model: String,
149    /// Confidence level of the projection
150    pub confidence_level: Option<f64>,
151    /// Additional metadata about the projection (JSON)
152    pub metadata: Option<String>,
153    /// Creation timestamp
154    pub created_at: DateTime<Utc>,
155    /// Last update timestamp
156    pub updated_at: DateTime<Utc>,
157}
158
159/// Represents a resource pricing entry in the system.
160#[derive(Debug, FromRow, Serialize, Deserialize, Clone)]
161pub struct ResourcePricing {
162    /// Unique identifier
163    pub id: i64,
164    /// Resource type ID
165    pub resource_type_id: i32,
166    /// Provider ID
167    pub provider_id: i64,
168    /// Region ID (optional)
169    pub region_id: Option<i64>,
170    /// Tier name (e.g., 'standard', 'premium')
171    pub tier_name: String,
172    /// Price per unit
173    pub unit_price: f64,
174    /// Currency code (e.g., 'USD')
175    pub currency: String,
176    /// When this pricing becomes effective
177    pub effective_from: DateTime<Utc>,
178    /// When this pricing expires (optional)
179    pub effective_to: Option<DateTime<Utc>>,
180    /// Pricing model (e.g., 'on-demand', 'reserved')
181    pub pricing_model: String,
182    /// Commitment period (e.g., '1-year', '3-year')
183    pub commitment_period: Option<String>,
184    /// Volume discount tiers (JSON)
185    pub volume_discount_tiers: Option<String>,
186    /// Creation timestamp
187    pub created_at: DateTime<Utc>,
188    /// Last update timestamp
189    pub updated_at: DateTime<Utc>,
190}
191
192/// Represents a cost allocation tag in the system.
193#[derive(Debug, FromRow, Serialize, Deserialize, Clone)]
194pub struct CostAllocationTag {
195    /// Unique identifier
196    pub id: i64,
197    /// Tag key
198    pub tag_key: String,
199    /// Tag value
200    pub tag_value: String,
201    /// Resource ID
202    pub resource_id: i64,
203    /// Resource type
204    pub resource_type: String,
205    /// Creation timestamp
206    pub created_at: DateTime<Utc>,
207    /// Last update timestamp
208    pub updated_at: DateTime<Utc>,
209}