use super::Error;
use serde::{Deserialize, Serialize};
use sn_dbc::Hash;
use xor_name::XorName;
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct DbcReason(Hash);
impl From<XorName> for DbcReason {
fn from(value: XorName) -> Self {
let bytes = value.0;
DbcReason(Hash::from(bytes))
}
}
impl From<Hash> for DbcReason {
fn from(value: Hash) -> Self {
DbcReason(value)
}
}
impl From<DbcReason> for Hash {
fn from(value: DbcReason) -> Hash {
value.0
}
}
impl std::str::FromStr for DbcReason {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(DbcReason::from(Hash::from_hex(s)?))
}
}
impl DbcReason {
pub fn is_empty(&self) -> bool {
self == &Default::default()
}
pub fn none() -> Self {
Default::default()
}
}