use std::sync::Arc;

#[derive(Clone)]
pub struct ChannelMetrics {
    pub messages_sent: Arc<std::sync::atomic::AtomicU64>,
    pub messages_received: Arc<std::sync::atomic::AtomicU64>,
    pub messages_failed: Arc<std::sync::atomic::AtomicU64>,
    pub active_connections: Arc<std::sync::atomic::AtomicI64>,
}

impl ChannelMetrics {
    pub fn new() -> Self {
        Self {
            messages_sent: Arc::new(std::sync::atomic::AtomicU64::new(0)),
            messages_received: Arc::new(std::sync::atomic::AtomicU64::new(0)),
            messages_failed: Arc::new(std::sync::atomic::AtomicU64::new(0)),
            active_connections: Arc::new(std::sync::atomic::AtomicI64::new(0)),
        }
    }

    pub fn increment_sent(&self) {
        self.messages_sent
            .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
    }

    pub fn increment_received(&self) {
        self.messages_received
            .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
    }

    pub fn increment_failed(&self) {
        self.messages_failed
            .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
    }

    pub fn increment_connections(&self) {
        self.active_connections
            .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
    }

    pub fn decrement_connections(&self) {
        self.active_connections
            .fetch_sub(1, std::sync::atomic::Ordering::Relaxed);
    }
}
