//! the message structs that are strictly just for the client (we should aim to completely remove these)
use nanoservices_utils::errors::NanoServiceError;
use tokio::sync::mpsc;
use tokio::sync::oneshot;

use crate::messages::client::message::TransactionMessage;

/// The messsage wrapper to enable returning a response to the sender.
///
/// # Fields
/// * `message`: The message to be sent to the router
/// * `tx`: the sender to send the response back to the initial sender from the router actor
pub struct WrappedRouterMessage {
	pub message: RouterMessage,
	pub tx: oneshot::Sender<RouterMessage>,
}

/// The message to be sent to the router.
///
/// # Variants
/// * `MakeConnection`: to make a connection using the string as the URL
/// * `ConnectionCreated`: a clarification of the connection created with the index of the allocator
/// * `GetConnection`: to get a random connection
/// * `ReturnConnection`: returns a random collection from the `GetConnection` request
/// * `CloseConnection`: to close the connection that belongs to the index
/// * `ConnectionClosed`: a confirmation that the connection is closed
/// * `Error`: an error
/// * `ShutdownConnectionPool`: shuts down the connection pool
#[derive(Debug)]
pub enum RouterMessage {
	MakeConnection(String),
	ConnectionCreated(usize),
	GetConnection,
	ReturnConnection((mpsc::Sender<TransactionMessage>, usize)),
	CloseConnection(usize),
	ConnectionClosed,
	Error(NanoServiceError),
	CloseConnectionPool,
	ConnectionPoolClosed,
}
