use grain_id::GrainId;
use serde::{Deserialize, Serialize};
use crate::hash::ContentHash;
use crate::hlc::Hlc;
use crate::vv::{Dot, VersionVector};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum Content {
File { hash: ContentHash, len: u64 },
Tombstone,
}
impl Content {
pub fn hash(&self) -> Option<ContentHash> {
match self {
Content::File { hash, .. } => Some(*hash),
Content::Tombstone => None,
}
}
pub fn is_tombstone(&self) -> bool {
matches!(self, Content::Tombstone)
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Entry {
pub path: String,
pub content: Content,
pub hlc: Hlc,
pub dot: Dot,
pub context: VersionVector,
pub author: GrainId,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct PathUpdate {
pub path: String,
pub versions: Vec<Entry>,
pub seen: VersionVector,
}