// Code generated by TofuPilot SDK Generator. DO NOT EDIT.

use std::time::Duration;
use crate::hooks::Hooks;

/// Configuration for the TofuPilot API client.
#[derive(Debug, Clone)]
pub struct ClientConfig {
    /// Base URL for the API (e.g. `https://www.tofupilot.app/api`)
    pub base_url: String,
    /// API key for authentication
    pub api_key: String,
    /// Request timeout
    pub timeout: Duration,
    /// Maximum number of retries for retryable errors (429, 5xx)
    pub max_retries: u32,
    /// User agent string
    pub user_agent: String,
    /// Request lifecycle hooks
    pub hooks: Hooks,
}

impl ClientConfig {
    /// Create a new configuration with the given API key.
    pub fn new(api_key: impl Into<String>) -> Self {
        Self {
            base_url: "https://www.tofupilot.app/api".to_string(),
            api_key: api_key.into(),
            timeout: Duration::from_secs(30),
            max_retries: 3,
            user_agent: format!("tofupilot-rust/{}", env!("CARGO_PKG_VERSION")),
            hooks: Hooks::new(),
        }
    }

    /// Set the base URL.
    pub fn base_url(mut self, url: impl Into<String>) -> Self {
        let mut base = url.into();
        if base.ends_with('/') {
            base.pop();
        }
        if !base.ends_with("/api") {
            base.push_str("/api");
        }
        self.base_url = base;
        self
    }

    /// Set the request timeout.
    pub fn timeout(mut self, timeout: Duration) -> Self {
        self.timeout = timeout;
        self
    }

    /// Set the maximum number of retries.
    pub fn max_retries(mut self, retries: u32) -> Self {
        self.max_retries = retries;
        self
    }

    /// Set request lifecycle hooks.
    pub fn hooks(mut self, hooks: Hooks) -> Self {
        self.hooks = hooks;
        self
    }
}
