use crate::entry::error::DecodeEntryError;
use crate::operation::error::ValidateOperationError;
use crate::operation::OperationId;
use crate::schema::SchemaId;
use crate::storage_provider::error::{EntryStorageError, LogStorageError, OperationStorageError};
#[derive(thiserror::Error, Debug)]
pub enum ValidationError {
#[error("Entry's claimed seq num of {0} does not match expected seq num of {1} for given public key and log")]
SeqNumDoesNotMatch(u64, u64),
#[error("Expected skiplink entry not found in store: public key {0}, log id {1}, seq num {2}")]
ExpectedSkiplinkNotFound(String, u64, u64),
#[error(
"Entry's claimed log id of {0} does not match expected next log id of {1} for given public key"
)]
LogIdDoesNotMatchNext(u64, u64),
#[error(
"Entry's claimed log id of {0} does not match existing log id of {1} for given public key and document id"
)]
LogIdDoesNotMatchExisting(u64, u64),
#[error("Entry with seq num 1 can not have skiplink")]
FirstEntryWithSkiplink,
#[error("Operation {0} claims incorrect schema {1} for document with schema {2}")]
InvalidClaimedSchema(OperationId, SchemaId, SchemaId),
#[error("Document is deleted")]
DocumentDeleted,
#[error("Max sequence number reached")]
MaxSeqNum,
#[error("Max log id reached")]
MaxLogId,
#[error("Previous operation {0} not found in store")]
PreviousOperationNotFound(OperationId),
#[error("Operations in passed document view id originate from different documents")]
InvalidDocumentViewId,
#[error(transparent)]
LogStoreError(#[from] LogStorageError),
#[error(transparent)]
EntryStoreError(#[from] EntryStorageError),
#[error(transparent)]
OperationStoreError(#[from] OperationStorageError),
}
#[derive(thiserror::Error, Debug)]
pub enum DomainError {
#[error("Max sequence number reached for public key {0} log {1}")]
MaxSeqNumReached(String, u64),
#[error("You are trying to update or delete a document which has been deleted")]
DeletedDocument,
#[error("Expected log id {0} not found when calculating next args")]
ExpectedLogIdNotFound(u64),
#[error(transparent)]
ValidationError(#[from] ValidationError),
#[error(transparent)]
LogStoreError(#[from] LogStorageError),
#[error(transparent)]
EntryStoreError(#[from] EntryStorageError),
#[error(transparent)]
OperationStoreError(#[from] OperationStorageError),
#[error(transparent)]
DecodeEntryError(#[from] DecodeEntryError),
#[error(transparent)]
ValidateOperationError(#[from] ValidateOperationError),
}