/*
 * LINE Messaging API(Insight)
 *
 * This document describes LINE Messaging API(Insight).
 *
 * The version of the OpenAPI document: 0.0.1
 *
 * Generated by: https://openapi-generator.tech
 */

use hyper;
use hyper::body::Bytes;
use http_body_util::Full;
use hyper_tls::HttpsConnector;
use hyper_util::client::legacy::connect::Connect;
use hyper_util::client::legacy::connect::HttpConnector;
use hyper_util::client::legacy::Client;
use hyper_util::rt::TokioExecutor;

type Connector = HttpsConnector<HttpConnector>;

pub struct Configuration<C: Connect = Connector>
where
    C: Clone + std::marker::Send + Sync + 'static,
{
    pub base_path: String,
    pub user_agent: Option<String>,
    pub client: Client<C, Full<Bytes>>,
    pub basic_auth: Option<BasicAuth>,
    pub oauth_access_token: Option<String>,
    pub api_key: Option<ApiKey>,
    // TODO: take an oauth2 token source, similar to the go one
}

pub type BasicAuth = (String, Option<String>);

pub struct ApiKey {
    pub prefix: Option<String>,
    pub key: String,
}

impl<C: Connect> Configuration<C>
where
    C: Clone + std::marker::Send + Sync,
{
    /// 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 line_insight::apis::configuration::Configuration;
    /// let api_config = Configuration {
    ///   basic_auth: Some(("user".into(), None)),
    ///   ..Configuration::new()
    /// };
    /// ```
    pub fn new(client: Client<Connector, Full<Bytes>>) -> Configuration<Connector> {
        Configuration::with_client(client)
    }
}

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 line_insight::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, Full<Bytes>>) -> Configuration<C> {
        Configuration {
            base_path: "https://api.line.me".to_owned(),
            user_agent: Some("OpenAPI-Generator/0.0.1/rust".to_owned()),
            client,
            basic_auth: None,
            oauth_access_token: None,
            api_key: None,
        }
    }
}
