1use serde::{Deserialize, Serialize};
2
3use super::{ResourceError, ResourceTrait, HOURS_PER_MONTH};
4
5use crate::VERSION;
6
7#[derive(Serialize, Deserialize, Debug)]
8pub struct Oos {
9 pub osc_cost_version: Option<String>,
10 pub account_id: Option<String>,
11 pub read_date_rfc3339: Option<String>,
12 pub region: Option<String>,
13 pub resource_id: Option<String>,
14 pub price_per_hour: Option<f32>,
15 pub price_per_month: Option<f32>,
16 pub size_gb: Option<f32>,
17 pub price_gb_per_month: f32,
18 pub number_files: u32,
19}
20
21impl ResourceTrait for Oos {
22 fn compute(&mut self) -> Result<(), ResourceError> {
23 let mut price_per_month = 0_f32;
24 price_per_month += self.size_gb.unwrap_or_default() * self.price_gb_per_month;
25 self.price_per_hour = Some(price_per_month / HOURS_PER_MONTH);
26 self.price_per_month = Some(price_per_month);
27 Ok(())
28 }
29
30 fn price_per_hour(&self) -> Result<f32, ResourceError> {
31 match self.price_per_hour {
32 Some(price) => Ok(price),
33 None => Err(ResourceError::NotComputed),
34 }
35 }
36}
37
38impl Default for Oos {
39 fn default() -> Self {
40 Self {
41 osc_cost_version: Some(String::from(VERSION)),
42 account_id: Some("".to_string()),
43 read_date_rfc3339: Some("".to_string()),
44 region: Some("".to_string()),
45 resource_id: None,
46 price_per_hour: Some(0.0),
47 price_per_month: Some(0.0),
48 size_gb: Some(0.0),
49 price_gb_per_month: 0.0,
50 number_files: 0,
51 }
52 }
53}