/*
 * Cloud Hypervisor API
 *
 * Local HTTP based API for managing and inspecting a cloud-hypervisor virtual machine.
 *
 * The version of the OpenAPI document: 0.3.0
 *
 * Generated by: https://openapi-generator.tech
 */

use hyper;
use hyper_util::client::legacy::Client;
use hyper_util::client::legacy::connect::Connect;
use hyper_util::client::legacy::connect::HttpConnector;
use hyper_util::rt::TokioExecutor;

pub struct Configuration<C: Connect = HttpConnector>
where
    C: Clone + std::marker::Send + Sync + 'static,
{
    pub base_path: String,
    pub user_agent: Option<String>,
    pub client: Client<C, String>,
}

impl Configuration<HttpConnector> {
    /// Construct a default [`Configuration`](Self) with a hyper client using a default
    /// [`HttpConnector`](hyper_util::client::legacy::connect::HttpConnector).
    ///
    /// Use [`with_client`](Configuration<T>::with_client) to construct a Configuration with a
    /// custom hyper client.
    ///
    /// # Example
    ///
    /// ```
    /// # use cloud_hypervisor_client::apis::configuration::Configuration;
    /// let api_config = Configuration::new();
    /// ```
    pub fn new() -> Configuration<HttpConnector> {
        Configuration::default()
    }
}

impl<C: Connect> Configuration<C>
where
    C: Clone + std::marker::Send + Sync,
{
    /// Construct a new Configuration with a custom hyper client.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::time::Duration;
    /// # use cloud_hypervisor_client::apis::configuration::Configuration;
    /// use hyper_util::client::legacy::Client;
    /// use hyper_util::rt::TokioExecutor;
    ///
    /// let client = Client::builder(TokioExecutor::new())
    ///   .pool_idle_timeout(Duration::from_secs(30))
    ///   .build_http();
    ///
    /// let api_config = Configuration::with_client(client);
    /// ```
    pub fn with_client(client: Client<C, String>) -> Configuration<C> {
        Configuration {
            base_path: "http://localhost/api/v1".to_owned(),
            user_agent: Some("cloud-hypervisor-client/0.3.0".to_owned()),
            client,
        }
    }
}

impl Default for Configuration<HttpConnector> {
    fn default() -> Self {
        let client = Client::builder(TokioExecutor::new()).build_http();
        Configuration::with_client(client)
    }
}
