use crate::element::Element;
use crate::zome_io::ExternIO;
use crate::CallbackResult;
use holo_hash::AnyDhtHash;
use holochain_serialized_bytes::prelude::*;
#[derive(
Clone, Copy, Hash, serde::Serialize, serde::Deserialize, PartialOrd, Ord, Debug, Eq, PartialEq,
)]
pub enum ValidationStatus {
Valid,
Rejected,
Abandoned,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)]
pub struct ValidateData {
pub element: Element,
pub validation_package: Option<ValidationPackage>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)]
pub enum ValidateCallbackResult {
Valid,
Invalid(String),
UnresolvedDependencies(Vec<AnyDhtHash>),
}
impl CallbackResult for ValidateCallbackResult {
fn is_definitive(&self) -> bool {
matches!(self, ValidateCallbackResult::Invalid(_))
}
}
impl From<ExternIO> for ValidateCallbackResult {
fn from(guest_output: ExternIO) -> Self {
match guest_output.decode() {
Ok(v) => v,
Err(e) => Self::Invalid(format!("{:?}", e)),
}
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)]
pub struct ValidationPackage(pub Vec<Element>);
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub enum RequiredValidationType {
Element,
SubChain,
Full,
Custom,
}
#[derive(Clone, PartialEq, Serialize, Deserialize, SerializedBytes, Debug)]
pub enum ValidationPackageCallbackResult {
Success(ValidationPackage),
Fail(String),
UnresolvedDependencies(Vec<AnyDhtHash>),
}
impl From<ExternIO> for ValidationPackageCallbackResult {
fn from(guest_output: ExternIO) -> Self {
match guest_output.decode() {
Ok(v) => v,
Err(e) => ValidationPackageCallbackResult::Fail(format!("{:?}", e)),
}
}
}
impl CallbackResult for ValidationPackageCallbackResult {
fn is_definitive(&self) -> bool {
matches!(self, ValidationPackageCallbackResult::Fail(_))
}
}
impl Default for RequiredValidationType {
fn default() -> Self {
Self::Element
}
}
impl ValidationPackage {
pub fn new(elements: Vec<Element>) -> Self {
Self(elements)
}
}