pub mod folders; pub mod hosts; pub(crate) mod rules; use std::fmt; use serde::{Deserialize, Serialize, de::DeserializeOwned}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum DomainType { Link, HostConfig, FolderConfig, ContactGroupConfig, HostGroupConfig, ServiceGroupConfig, } impl fmt::Display for DomainType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { DomainType::HostConfig => write!(f, "host_config"), DomainType::FolderConfig => write!(f, "folder_config"), DomainType::Link => write!(f, "link"), DomainType::ContactGroupConfig => write!(f, "contact_group_config"), DomainType::HostGroupConfig => write!(f, "host_group_config"), DomainType::ServiceGroupConfig => write!(f, "service_group_config"), } } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "UPPERCASE")] pub enum HttpMethod { Get, Put, Post, Delete, } // #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] // pub(crate) struct RelationLink { // #[serde(rename = "domainType")] // pub domain_type: DomainType, // pub rel: String, // pub href: String, // pub method: HttpMethod, // pub r#type: String, // #[serde(default)] // pub title: Option, // // body_params: HashMap // i will deal with this later // } #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub(crate) struct DomainObject { pub domain_type: DomainType, pub id: String, #[serde(default)] pub title: Option, pub extensions: E, // not used in this library // #[serde(default)] // pub links: Vec, // deprecated in favour of links // pub members: M } #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub(crate) struct DomainCollection { pub domain_type: DomainType, pub id: String, #[serde(default)] pub title: Option, pub value: Vec>, // not used in this library // #[serde(default)] // pub links: Vec, // pub extensions: Option, } pub trait DomainExtension: DeserializeOwned + Serialize { const DOMAIN_TYPE: DomainType; type CreationRequest: Serialize; type CreationQuery: Serialize; type ReadQuery: Serialize; type UpdateRequest: Serialize; type DeleteQuery: Serialize; } // these are essential tags for domain extensions to signal that bulk operations are possible // not every extension supports bulk operations. and not all extensions that do support all of them // and those that do tend to have a bit different types pub trait BulkCreateDomainExtension: DomainExtension {} pub trait BulkReadDomainExtension: DomainExtension { type BulkReadQuery: Serialize; } pub trait BulkUpdateDomainExtension: DomainExtension { type BulkUpdateRequest: Serialize; } pub trait BulkDeleteDomainExtension: DomainExtension {}