use diesel::result::{ConnectionError as DieselConnectionError, Error as DieselError};
use tari_comms::{builder::CommsError, connection::NetAddressError, message::MessageError};
use tari_comms_dht::outbound::DhtOutboundError;
use tari_crypto::tari_utilities::{hex::HexError, message_format::MessageFormatError};
use tari_p2p::services::liveness::error::LivenessError;
use tari_service_framework::reply_channel::TransportChannelError;
use thiserror::Error;
use tokio_executor::threadpool::BlockingError;
#[derive(Debug, Error)]
pub enum TextMessageError {
#[error("Message format error: `{0}`")]
MessageFormatError(#[from] MessageFormatError),
#[error("Message error: `{0}`")]
MessageError(#[from] MessageError),
#[error("Outbound error: `{0}`")]
OutboundError(#[from] DhtOutboundError),
#[error("Comms services error: `{0}`")]
CommsServicesError(#[from] CommsError),
#[error("Hex error: `{0}`")]
HexError(#[from] HexError),
#[error("Database error: `{0}`")]
DatabaseError(#[from] DieselError),
#[error("Transport channel error: `{0}`")]
TransportChannelError(#[from] TransportChannelError),
#[error("Database migration error: `{0}`")]
DatabaseMigrationError(String),
#[error("Net address error: `{0}`")]
NetAddressError(#[from] NetAddressError),
#[error("Database connection error: `{0}`")]
DatabaseConnectionError(#[from] DieselConnectionError),
#[error("Blocking error: `{0}`")]
BlockingError(#[from] BlockingError),
#[error("R2d2 error")]
R2d2Error,
#[error("Liveness error: `{0}`")]
LivenessError(#[from] LivenessError),
#[error("An error has occurred reading or writing the event subscriber stream")]
EventStreamError,
#[error("If a received TextMessageAck doesn't matching any pending messages")]
MessageNotFound,
#[error("Failed to send from API")]
ApiSendFailed,
#[error("Failed to receive in API from service")]
ApiReceiveFailed,
#[error("The Outbound Message Service is not initialized")]
OMSNotInitialized,
#[error("The Comms service stack is not initialized")]
CommsNotInitialized,
#[error("Received an unexpected API response")]
UnexpectedApiResponse,
#[error("Contact not found")]
ContactNotFound,
#[error("Contact already exists")]
ContactAlreadyExists,
#[error("There was an error updating a row in the database")]
DatabaseUpdateError,
#[error("Error retrieving settings")]
SettingsReadError,
}