use prikk_error::Result;
use crate::{CanonicalEncode, CanonicalWriter};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MerkleRoot(pub [u8; 32]);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u16)]
pub enum Intent {
Feature = 1,
Fix = 2,
Refactor = 3,
Docs = 4,
Test = 5,
}
impl Intent {
#[must_use]
pub const fn code(self) -> u16 {
self as u16
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct OperationConditionEntry {
pub key: String,
pub value: OperationCondition,
}
impl CanonicalEncode for OperationConditionEntry {
fn encode_canonical(&self, writer: &mut CanonicalWriter) -> Result<()> {
writer.field_string(1, &self.key)?;
writer.field_record(2, &self.value)?;
Ok(())
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum OperationCondition {
OldContentHash(Vec<u8>),
AnchorExists(String),
PathExists(String),
PathAbsent(String),
}
impl CanonicalEncode for OperationCondition {
fn encode_canonical(&self, writer: &mut CanonicalWriter) -> Result<()> {
match self {
Self::OldContentHash(hash) => {
writer.field_u32(1, 1)?;
writer.field_bytes(2, hash)?;
}
Self::AnchorExists(anchor) => {
writer.field_u32(1, 2)?;
writer.field_string(2, anchor)?;
}
Self::PathExists(path) => {
writer.field_u32(1, 3)?;
writer.field_string(2, path)?;
}
Self::PathAbsent(path) => {
writer.field_u32(1, 4)?;
writer.field_string(2, path)?;
}
}
Ok(())
}
}