use std::io;
use tokio::sync::mpsc::error::TrySendError;
use crate::server::request::ZingoIndexerRequest;
#[derive(Debug, thiserror::Error)]
pub enum QueueError<T> {
#[error("Queue Full")]
QueueFull(T),
#[error("Queue Empty")]
QueueEmpty,
#[error("Queue Disconnected")]
QueueClosed,
}
#[derive(Debug, thiserror::Error)]
pub enum RequestError {
#[error("Incorrect variant")]
IncorrectVariant,
#[error("System time error: {0}")]
SystemTimeError(#[from] std::time::SystemTimeError),
}
#[derive(Debug, thiserror::Error)]
pub enum IngestorError {
#[error("Request error: {0}")]
RequestError(#[from] RequestError),
#[error("Failed to accept TcpStream: {0}")]
ClientConnectionError(#[from] io::Error),
#[error("Failed to send request to the queue: {0}")]
QueuePushError(#[from] TrySendError<ZingoIndexerRequest>),
}
#[derive(Debug, thiserror::Error)]
pub enum WorkerError {
#[error("Tonic transport error: {0}")]
TonicTransportError(#[from] tonic::transport::Error),
#[error("Tokio join error: {0}")]
TokioJoinError(#[from] tokio::task::JoinError),
#[error("Worker Pool Full")]
WorkerPoolFull,
#[error("Worker Pool a idle")]
WorkerPoolIdle,
}
#[derive(Debug, thiserror::Error)]
pub enum ServerError {
#[error("Request error: {0}")]
RequestError(#[from] RequestError),
#[error("Ingestor error: {0}")]
IngestorError(#[from] IngestorError),
#[error("Worker error: {0}")]
WorkerError(#[from] WorkerError),
#[error("Server configuration error: {0}")]
ServerConfigError(String),
}