use crdts::Dot;
use sn_data_types::{Credit, Debit, Error as DtError, PublicKey, Token};
use thiserror::Error;
#[derive(Error, Debug, PartialEq, Clone)]
#[non_exhaustive]
pub enum Error {
#[error("Sender missing from actors")]
MissingSender,
#[error("Recipient missing from actors")]
MissingRecipient,
#[error("Sender and recipient are the same")]
SameSenderAndRecipient,
#[error("Current pending debit has not been completed")]
DebitPending,
#[error("PublicKey provided by the transfer was never a part of the section chain.")]
SectionKeyNeverExisted,
#[error("Debit already proposed or out of order")]
DebitProposed,
#[error("Credit and debit ids do not match")]
CreditDebitIdMismatch,
#[error("Credit and debit value do not match")]
CreditDebitValueMismatch,
#[error("Validation not intended for this actor")]
WrongValidationActor,
#[error("Could not find the expected transfer id among accumulating validations")]
PendingTransferNotFound,
#[error("Validation not expected at this actor {0:?}")]
NoSetForDebitId(Dot<PublicKey>),
#[error("Transfer not expected for this actor {0:?}")]
NoSetForTransferId(Dot<PublicKey>),
#[error(
"Operation out of order: debit's counter is '{0}', actor next expected op count is '{1}'"
)]
OperationOutOfOrder(u64, u64),
#[error("Operation out of order debit counter should be 0")]
ShouldBeInitialOperation,
#[error("There was no valid history found for provided actor.")]
NoActorHistory,
#[error("Transfer amount must be greater than zero")]
ZeroValueTransfer,
#[error("Validation already received")]
ValidatedAlready,
#[error("Debit is not from wallet {0}. Debit: {1:?}")]
DebitDoesNotBelong(PublicKey, Debit),
#[error("Credit is not to wallet {0}. Credit: {1:?}")]
CreditDoesNotBelong(PublicKey, Credit),
#[error("Overflow when subtracting {0} from balance of: {1}")]
SubtractionOverflow(Token, Token),
#[error("Overflow when adding balance {0} and credit of: {1}")]
AdditionOverflow(Token, Token),
#[error("Receive validation failed")]
ReceiveValidationFailed,
#[error("TransferCreationFailed")]
TransferCreationFailed,
#[error("SenderValidationFailed")]
SenderValidationFailed,
#[error("RegisterProofFailed")]
RegisterProofFailed,
#[error("InvalidCreditOrDebit")]
InvalidCreditOrDebit,
#[error("CouldNotGetWalletForReplica")]
CouldNotGetWalletForReplica,
#[error("CouldNotFindGroup")]
CouldNotFindGroup,
#[error("ReceivePropagationFailed")]
ReceivePropagationFailed,
#[error("SyncFailed")]
SyncFailed,
#[error("ValidationFailed")]
ValidationFailed,
#[error("GenesisFailed")]
GenesisFailed,
#[error("Unknown error: {0}")]
Unknown(String),
#[error("{0} Wallet not found locally.")]
WalletNotFound(PublicKey),
#[error("Could not aggregate with given signature shares")]
CannotAggregate,
#[error("Signature is not valid")]
InvalidSignature,
#[error("Operation is not valid")]
InvalidOperation,
#[error("Owner is not valid")]
InvalidOwner,
#[error("Insufficient balance to complete this operation")]
InsufficientBalance,
#[error("No such sender key balance")]
NoSuchSender,
#[error("No such recipient key balance")]
NoSuchRecipient,
#[error("Key already exists")]
KeyExists,
#[error(transparent)]
NetworkDataError(#[from] DtError),
#[error("Serialisation error. {0}")]
Serialisation(String),
}