use std::fmt::{Formatter, Display};

#[derive(Debug)]
pub enum MessageQueueError {
    // The topic provided does not exist
    NonExistentTopic(String),

    // Failed to publish a message to the message queue
    FailedToPublish(String),

    // Failed to connect to the message queue's underlying client
    ClientConnectionError(String),

    // Failed to construct the message queue's underlying client
    ConfigConstructionError(String),

    // Failed to connect to the subscription
    SubscriptionConnectionError(String),

    // Failed to decode the message data
    DecodeError(String),

    SubscriptionNotConfiguredError(String),
}

impl Display for MessageQueueError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            MessageQueueError::NonExistentTopic(topic) => {
                write!(f, "The topic {} does not exist", topic)
            }
            MessageQueueError::FailedToPublish(e) => {
                write!(f, "Failed to publish message: {}", e)
            }
            MessageQueueError::ClientConnectionError(e) => {
                write!(
                    f,
                    "Failed to connect to the message queue's underlying client: {}",
                    e
                )
            }
            MessageQueueError::ConfigConstructionError(e) => {
                write!(
                    f,
                    "Failed to construct the message queue's underlying client: {}",
                    e
                )
            }
            MessageQueueError::SubscriptionConnectionError(e) => {
                write!(f, "Failed to connect to the subscription: {}", e)
            }
            MessageQueueError::DecodeError(e) => {
                write!(f, "Failed to decode the message data: {}", e)
            }
            MessageQueueError::SubscriptionNotConfiguredError(e) => {
                write!(f, "Subscription not configured: {}", e)
            }
        }
    }
}
