//! Defines the logging of transaction messages sent to the client router.
use crate::logging::messages::connections::ping::PingJourney;
use crate::logging::messages::transactions::base::TransactionJourney;
use crate::messages::client::message::TransactionMessage;
use crate::messages::server::interface::ServerMessage;

/// Logs a transaction message that the client router has received.
///
/// # Arguments
/// * `message`: the transaction message that the client router has received
pub fn log_client_router_message(message: &TransactionMessage) {
	if let TransactionMessage::TransactionOperation(unwrapped_message) = message {
		if let ServerMessage::Ping(_) = unwrapped_message.message {
			tracing::trace!(
				"{}",
				PingJourney::RecievedByClientRouter.to_log(&unwrapped_message.connection_id)
			);
		}
		let tx_pointer = TransactionJourney::RecievedByClientRouter;
		let log = tx_pointer.from_wrapped_server_message(unwrapped_message);
		if log.is_some() {
			tracing::trace!("{}", log.unwrap());
		}
	}
}
