//!
//! 数据持久化客户端
//!
//! 提供一个类型化的接口，用于与 `data-persistence-service` 进行通信。
//!

use crate::error::Result;
use common_contracts::config_models::LlmProvidersConfig;
use tracing::info;

#[derive(Clone)]
pub struct PersistenceClient {
    client: reqwest::Client,
    base_url: String,
}

impl PersistenceClient {
    pub fn new(base_url: String) -> Self {
        Self {
            client: reqwest::Client::new(),
            base_url,
        }
    }

    // --- Config Fetching & Updating Methods ---

    pub async fn get_llm_providers_config(&self) -> Result<LlmProvidersConfig> {
        let url = format!("{}/api/v1/configs/llm_providers", self.base_url);
        info!("Fetching LLM providers config from {}", url);
        let config = self
            .client
            .get(&url)
            .send()
            .await?
            .error_for_status()?
            .json::<LlmProvidersConfig>()
            .await?;
        Ok(config)
    }

}
