use serde::{Deserialize, Serialize};
use super::{ResourceError, ResourceTrait, HOURS_PER_MONTH};
use crate::VERSION;
#[derive(Serialize, Deserialize, Debug)]
pub struct Oos {
pub osc_cost_version: Option<String>,
pub account_id: Option<String>,
pub read_date_rfc3339: Option<String>,
pub region: Option<String>,
pub resource_id: Option<String>,
pub price_per_hour: Option<f32>,
pub price_per_month: Option<f32>,
pub size_gb: Option<f32>,
pub price_gb_per_month: f32,
pub number_files: u32,
}
impl ResourceTrait for Oos {
fn compute(&mut self) -> Result<(), ResourceError> {
let mut price_per_month = 0_f32;
price_per_month += self.size_gb.unwrap_or_default() * self.price_gb_per_month;
self.price_per_hour = Some(price_per_month / HOURS_PER_MONTH);
self.price_per_month = Some(price_per_month);
Ok(())
}
fn price_per_hour(&self) -> Result<f32, ResourceError> {
match self.price_per_hour {
Some(price) => Ok(price),
None => Err(ResourceError::NotComputed),
}
}
}
impl Default for Oos {
fn default() -> Self {
Self {
osc_cost_version: Some(String::from(VERSION)),
account_id: Some("".to_string()),
read_date_rfc3339: Some("".to_string()),
region: Some("".to_string()),
resource_id: None,
price_per_hour: Some(0.0),
price_per_month: Some(0.0),
size_gb: Some(0.0),
price_gb_per_month: 0.0,
number_files: 0,
}
}
}