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

const TARGET: &str = "surrealcs::kernel::client::reader";

/// Logs a transaction message that the client writer has received.
///
/// # Arguments
/// * `message`: the transaction message that the client writer has received
pub fn log_client_writer_message(message: &TransactionMessage) {
	match message {
		// Log ping messages separately
		TransactionMessage::Ping((_, connection_id)) => {
			tracing::trace!(target: TARGET, connection_id = %connection_id, "{}", PingJourney::RecievedByClientWriter.as_str());
		}
		// Log other transaction messages
		TransactionMessage::TransactionOperation(operation) => {
			let tx_pointer = TransactionJourney::RecievedByClientWriter;
			let log = tx_pointer.from_wrapped_server_message(operation);
			if let Some(log) = log {
				tracing::trace!(target: TARGET, "{log}");
			}
		}
		_ => {}
	}
}
