//! HTTP client for fetching medical information

use crate::error::Result;
use reqwest::Client;
use std::time::Duration;

/// Main client for Hospital Helpers
#[derive(Clone, Debug)]
pub struct HHClient {
    client: Client,
}

impl HHClient {
    /// Create a new HH client with default settings
    pub fn new() -> Self {
        let client = Client::builder()
            .timeout(Duration::from_secs(30))
            .user_agent("Hospital-Helpers/0.1.0")
            .build()
            .expect("Failed to build HTTP client");

        Self { client }
    }

    /// Create a new HH client with custom reqwest client
    pub fn with_client(client: Client) -> Self {
        Self { client }
    }

    /// Get a reference to the internal HTTP client
    pub fn client(&self) -> &Client {
        &self.client
    }

    /// Fetch HTML content from a URL
    pub async fn fetch_html(&self, url: &str) -> Result<String> {
        let response = self.client.get(url).send().await?;
        let html = response.text().await?;
        Ok(html)
    }
}

impl Default for HHClient {
    fn default() -> Self {
        Self::new()
    }
}

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

    #[test]
    fn test_client_creation() {
        let client = HHClient::new();
        assert!(client.client().timeout().is_some());
    }
}
