//! Per-host Connection Pool Management
//!
//! Manages individual connection pools for each host with:
//! - Pool size constraints
//! - Connection lifecycle management
//! - Health tracking
//!
//! Phase 1: Core structure
//! Phase 4: Integration with circuit breakers

use std::collections::VecDeque;
use std::sync::Arc;

use crate::ssh::pool::connection::PooledConnection;

/// Per-host SSH connection pool
#[derive(Debug)]
pub struct ServerConnectionPool {
    /// Host name
    pub host: String,
    /// Available connections
    pub available: Arc<tokio::sync::RwLock<VecDeque<PooledConnection>>>,
    /// Connections currently in use
    pub in_use: Arc<tokio::sync::RwLock<Vec<PooledConnection>>>,
    // config: Arc<SshPoolConfig>, // Phase 2
    // semaphore: Arc<Semaphore>,  // Phase 1 - TODO
}

impl ServerConnectionPool {
    /// Create a new per-host connection pool
    pub fn new(host: String) -> Self {
        Self {
            host,
            available: Arc::new(tokio::sync::RwLock::new(VecDeque::new())),
            in_use: Arc::new(tokio::sync::RwLock::new(Vec::new())),
        }
    }

    /// Get number of available connections
    pub async fn available_count(&self) -> usize {
        self.available.read().await.len()
    }

    /// Get number of in-use connections
    pub async fn in_use_count(&self) -> usize {
        self.in_use.read().await.len()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[tokio::test]
    async fn test_pool_creation() {
        let pool = ServerConnectionPool::new("host.example.com".to_string());
        assert_eq!(pool.available_count().await, 0);
        assert_eq!(pool.in_use_count().await, 0);
    }
}
