use content_addressable::{ContentAddressable, ContentError, ContentId, RawContentId};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum RootKind {
OperatorPrompt,
UserAction,
HarnessEvent,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RootEvent {
pub kind: RootKind,
pub content: RawContentId,
pub seq: u64,
}
impl RootEvent {
#[must_use]
pub fn new(kind: RootKind, material: &[u8], seq: u64) -> Self {
Self {
kind,
content: RawContentId::from_content(material),
seq,
}
}
pub fn id(&self) -> Result<ContentId, ContentError> {
self.content_id()
}
}
impl ContentAddressable for RootEvent {
fn canonical_form(&self) -> Result<Vec<u8>, ContentError> {
content_addressable::canonical::to_canonical_dagcbor(self)
}
}