pub mod create_pool;
pub mod delete_pool;
pub mod pool_details;
use crate::framework::response::ApiResult;
use chrono::offset::Utc;
use chrono::DateTime;
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use std::net::IpAddr;
#[derive(Eq, PartialEq, Deserialize, Serialize, Clone, Debug)]
pub struct Pool {
pub id: String,
pub created_on: DateTime<Utc>,
pub modified_on: DateTime<Utc>,
pub description: String,
pub name: String,
pub enabled: bool,
pub minimum_origins: u8,
pub monitor: String,
pub check_regions: Option<Vec<String>>,
pub origins: HashSet<Origin>,
pub notification_email: String,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct Origin {
pub name: String,
pub address: IpAddr,
pub enabled: bool,
pub weight: f64,
}
impl PartialEq for Origin {
fn eq(&self, other: &Self) -> bool {
let diff_is_small = (self.weight - other.weight).abs() < 0.01;
self.name == other.name
&& self.address == other.address
&& self.enabled == other.enabled
&& diff_is_small
}
}
impl Eq for Origin {}
impl Hash for Origin {
fn hash<H: Hasher>(&self, state: &mut H) {
self.name.hash(state);
self.address.hash(state);
self.enabled.hash(state);
self.weight.to_bits().hash(state);
}
}
impl ApiResult for Origin {}
impl ApiResult for Pool {}