use serde::{Serialize,Deserialize};
use url::Url;
use uuid::Uuid;
use crate::database::id::EntityGenerationId;
use crate::time::UtcTimespan;
use crate::time::UtcTimestamp;
#[derive(Debug,Clone,PartialEq,Eq,Serialize,Deserialize)]
pub struct EntityGeneration {
pub url: Url,
pub uuid: Uuid,
pub first_seen: UtcTimestamp,
pub last_seen: UtcTimestamp,
pub marked_duplicate: bool,
pub time_end_confirmed: Option<UtcTimestamp>,
}
impl EntityGeneration {
pub fn get_confirmed_lifetime(&self) -> UtcTimespan {
UtcTimespan::new(Some(self.first_seen), Some(self.last_seen))
}
pub fn max_condifrmed_lifetime(&self) -> UtcTimespan {
UtcTimespan::new(Some(self.first_seen), self.time_end_confirmed)
}
pub fn is_still_alive(&self) -> bool {
self.time_end_confirmed.is_none()
}
}
#[derive(Clone)]
pub struct WithEntityGenerationId<T> {
pub entity_generation_id: EntityGenerationId,
pub data: T
}
pub trait IntoWithEntityGenerationId<T>
where T: Clone {
fn with_entity_generation_id(self, id: EntityGenerationId) -> WithEntityGenerationId<T>;
}
impl<T> IntoWithEntityGenerationId<T> for T
where T: Clone {
fn with_entity_generation_id(self, id: EntityGenerationId) -> WithEntityGenerationId<T> {
WithEntityGenerationId {
entity_generation_id: id,
data: self,
}
}
}
#[derive(Clone, Deserialize, Serialize)]
pub struct WithEntityGenerationUuid<T> {
pub entity_generation_uuid: Uuid,
#[serde(flatten)]
pub data: T
}
pub trait IntoWithEntityGenerationUuid<T>
where T: Clone {
fn with_entity_generation_uuid(self, uuid: Uuid) -> WithEntityGenerationUuid<T>;
}
impl<T> IntoWithEntityGenerationUuid<T> for T
where T: Clone {
fn with_entity_generation_uuid(self, uuid: Uuid) -> WithEntityGenerationUuid<T> {
WithEntityGenerationUuid {
entity_generation_uuid: uuid,
data: self,
}
}
}