use crate::section_info::Error as TargetSectionError;
use serde::{Deserialize, Serialize};
use sn_data_types::DataAddress;
use sn_data_types::PublicKey;
use std::result;
use thiserror::Error;
pub type Result<T, E = Error> = result::Result<T, E>;
#[derive(Error, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[non_exhaustive]
#[allow(clippy::large_enum_variant)]
pub enum Error {
#[error("Unsupported messaging protocol version: {0}")]
UnsupportedVersion(u16),
#[error("Unsupported payload serialization: {0}")]
UnsupportedSerialization(u16),
#[error("Access denied for PublicKey: {0}")]
AccessDenied(PublicKey),
#[error("Signature verification error: {0}")]
SignatureVerification(String),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Requested data not found: {0:?}")]
DataNotFound(DataAddress),
#[error("No history found for PublicKey: {0}")]
NoHistoryForPublicKey(sn_data_types::PublicKey),
#[error("Failed to write file")]
FailedToWriteFile,
#[error("Data provided already exists")]
DataExists,
#[error("Requested entry not found")]
NoSuchEntry,
#[error("Exceeded a limit on a number of entries")]
TooManyEntries,
#[error("Key does not exist")]
NoSuchKey,
#[error("Node does not have sufficient space to store chunk")]
NotEnoughSpace,
#[error("Duplicate entries provided")]
DuplicateEntryKeys,
#[error("Invalid owner key: {0}")]
InvalidOwners(sn_data_types::PublicKey),
#[error("No policy has been set for this data")]
PolicyNotSet,
#[error("Invalid version provided: {0}")]
InvalidSuccessor(u64),
#[error("Invalid owners version provided: {0}")]
InvalidOwnersSuccessor(u64),
#[error("Operation is not causally ready. Ensure you have the full history of operations.")]
OpNotCausallyReady,
#[error("Invalid permission version provided: {0}")]
InvalidPermissionsSuccessor(u64),
#[error("Invalid operation: {0}")]
InvalidOperation(String),
#[error("Sign key and signature type do not match")]
SigningKeyTypeMismatch,
#[error("Invalid signature")]
InvalidSignature,
#[error("Duplicate message id received")]
DuplicateMessageId,
#[error("Lost precision on the number of coins during parsing")]
LossOfPrecision,
#[error("The token amount would exceed the maximum value (u64::MAX)")]
ExcessiveValue,
#[error("Transaction Id already exists")]
TransactionIdExists,
#[error("Insufficient payment provided to complete this operation")]
InsufficientPayment,
#[error("No such key exists")]
NoSuchBalance,
#[error("No such sender key balance")]
NoSuchSender,
#[error("No such recipient key balance")]
NoSuchRecipient,
#[error("Key already exists")]
BalanceExists,
#[error("Size of the structure exceeds the limit")]
ExceededSize,
#[error("CRDT operation missing actor signature")]
CrdtMissingOpSignature,
#[error("CRDT data is in an unexpected and/or inconsistent state. No data found for current policy.")]
CrdtUnexpectedState,
#[error("Entry already exists {0}")]
EntryExists(u8),
#[error("Payment registration failed")]
PaymentFailed,
#[error("Failed to delete requested data")]
FailedToDelete,
#[error("Node does not currently manage any section funds")]
NoSectionFunds,
#[error("Node does not currently manage any section metadata")]
NoSectionMetaData,
#[error("Node does not currently manage any immutable chunks")]
NoImmutableChunks,
#[error("Cannot complete request due to churning of funds")]
NodeChurningFunds,
#[error("Node is not being relocated")]
NodeWasNotRelocated,
#[error("Target section error")]
TargetSection(#[from] TargetSectionError),
}