//! Defines the logging structure to capture the journey of a ping message.

/// The journey of a ping message.
///
/// This is used to log the journey of a ping message through the server.
///
/// # Fields
/// * `SentByActor`: the ping message was sent by the inital ping actor
/// * `RecievedByClientWriter`: the ping message was recieved by the client writer to be sent to the server
/// * `RecievedByServerReader`: the ping message was recieved by the server reader to be sent to the server router
/// * `RecievedByServerRouter`: the ping message was recieved by the server router to be sent to the server writer
/// * `RecievedByServerWriter`: the ping message was recieved by the server writer to be sent to the client reader
/// * `RecievedByClientReader`: the ping message was recieved by the client reader to be sent to the client router
/// * `RecievedByClientRouter`: the ping message was recieved by the client router to be sent to the inital ping actor
/// * `RecievedByActor`: the ping message was recieved by the inital ping actor
pub enum PingJourney {
	SentByActor,
	RecievedByClientWriter,
	RecievedByServerReader,
	RecievedByServerRouter,
	RecievedByServerWriter,
	RecievedByClientReader,
	RecievedByClientRouter,
	RecievedByActor,
}

impl PingJourney {
	/// Converts the ping journey step to a string for logging.
	///
	/// # Returns
	/// A string representation of the ping journey step.
	pub fn as_str(&self) -> &'static str {
		match self {
			PingJourney::SentByActor => "Sent by actor", // logged in client/src/utils/ping_actor.rs
			PingJourney::RecievedByClientWriter => "Recieved by client writer", // logged in client/src/connection/writer.rs
			PingJourney::RecievedByServerReader => "Recieved by server reader", // logged in server/src/connection/reader.rs
			PingJourney::RecievedByServerRouter => "Recieved by server router", // logged in server/src/connection/router.rs
			PingJourney::RecievedByServerWriter => "Recieved by server writer", // logged in server/src/connection/writer.rs
			PingJourney::RecievedByClientReader => "Recieved by client reader", // logged in client/src/connection/reader.rs
			PingJourney::RecievedByClientRouter => "Recieved by client router", // logged in client/src/connection/router.rs
			PingJourney::RecievedByActor => "Recieved by actor", // logged in client/src/utils/ping_actor.rs
		}
	}

	/// Converts the ping journey step to a string for logging.
	///
	/// # Arguments
	/// * `connection_id`: the ID of the connection that the ping message is associated with
	///
	/// # Returns
	/// A string representation of the ping journey step.
	pub fn to_log(&self, connection_id: &String) -> String {
		format!("connection ping: {} -> [{}]", self.as_str(), connection_id)
	}
}
