use std::fmt::Debug;
use std::time::Duration;
use dapi_grpc::mock::Mockable;
use dpp::version::PlatformVersionError;
use dpp::ProtocolError;
use rs_dapi_client::DapiClientError;
pub use drive_proof_verifier::error::ContextProviderError;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("SDK misconfigured: {0}")]
Config(String),
#[error("Drive error: {0}")]
Drive(#[from] drive::error::Error),
#[error("Protocol error: {0}")]
Protocol(#[from] ProtocolError),
#[error("Proof verification error: {0}")]
Proof(#[from] drive_proof_verifier::Error),
#[error("Invalid Proved Response error: {0}")]
InvalidProvedResponse(String),
#[error("Dapi client error: {0}")]
DapiClientError(String),
#[cfg(feature = "mocks")]
#[error("Dapi mocks error: {0}")]
DapiMocksError(#[from] rs_dapi_client::mock::MockError),
#[error("Dash core error: {0}")]
CoreError(#[from] dpp::dashcore::Error),
#[error("Dash core error: {0}")]
MerkleBlockError(#[from] dpp::dashcore::merkle_tree::MerkleBlockError),
#[error("Core client error: {0}")]
CoreClientError(#[from] dashcore_rpc::Error),
#[error("Required {0} not found: {1}")]
MissingDependency(String, String),
#[error("Total credits in Platform are not found; it should never happen")]
TotalCreditsNotFound,
#[error("No epoch found on Platform; it should never happen")]
EpochNotFound,
#[error("SDK operation timeout {} secs reached: {1}", .0.as_secs())]
TimeoutReached(Duration, String),
#[error("SDK error: {0}")]
Generic(String),
#[error("Context provider error: {0}")]
ContextProviderError(#[from] ContextProviderError),
#[error("Operation cancelled: {0}")]
Cancelled(String),
}
impl<T: Debug + Mockable> From<DapiClientError<T>> for Error {
fn from(value: DapiClientError<T>) -> Self {
Self::DapiClientError(format!("{:?}", value))
}
}
impl From<PlatformVersionError> for Error {
fn from(value: PlatformVersionError) -> Self {
Self::Protocol(value.into())
}
}