use crate::dbs;
use crate::messaging::MessageId;
use crate::routing::Prefix;
use crate::types::{DataAddress, PublicKey};
use std::io;
use thiserror::Error;
use xor_name::XorName;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[allow(clippy::large_enum_variant)]
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("Attempted Adult operation when not an Adult")]
NotAnAdult,
#[error("Attempted Elder operation when not an Elder")]
NotAnElder,
#[error("Not enough Adults available in Section({0:?}) to perform operation")]
NoAdults(Prefix),
#[error("Database error:: {0}")]
Database(#[from] dbs::Error),
#[error("Not section public key returned from routing")]
NoSectionPublicKey,
#[error("Not section public key set returned from routing")]
NoSectionPublicKeySet,
#[error("Not section public key returned from routing for xorname {0}")]
NoSectionPublicKeyKnown(XorName),
#[error("No such data: {0:?}")]
NoSuchData(DataAddress),
#[error("Could not create temp store: {0}")]
TempDirCreationFailed(String),
#[error("Data already exists at this node")]
DataExists,
#[error("I/O error: {0}")]
Io(#[from] io::Error),
#[error("JSON serialisation error:: {0}")]
JsonSerialisation(#[from] serde_json::Error),
#[error("Bincode error:: {0}")]
Bincode(#[from] bincode::Error),
#[error("Network service message error:: {0}")]
ServiceMsg(#[from] crate::messaging::data::Error),
#[error("Service error:: {0:?}")]
ServiceError(crate::messaging::data::ServiceError),
#[error("Network message error:: {0}")]
Message(#[from] crate::messaging::Error),
#[error("Network data error:: {0}")]
NetworkData(#[from] crate::types::Error),
#[error("Routing error:: {0}")]
Routing(#[from] crate::routing::Error),
#[error("Message with id: '{0:?}' is invalid. {1}")]
InvalidMessage(MessageId, String),
#[error("Provided PublicKey is not a valid owner. Provided PublicKey: {0}")]
InvalidOwner(PublicKey),
#[error("Invalid operation: {0}")]
InvalidOperation(String),
#[error("No mapping to sn_messages error is set up for this NodeError {0}")]
NoErrorMapping(String),
#[error("Logic error: {0}")]
Logic(String),
#[error("Timeout when trying to join the network")]
JoinTimeout,
#[error("Configuration error: {0}")]
Configuration(String),
#[error("Sled error:: {0}")]
Sled(#[from] sled::Error),
}