pub mod client;
pub mod qdrant;
pub mod service;

pub use client::{EmbedClient, EmbedPayload, EmbedVector, SearchResult};
pub use qdrant::QdrantClient;
pub use service::{EmbedService, Embeddable};

pub async fn new_embed_client(config: &config::AppConfig) -> crate::Result<EmbedClient> {
    let base_url = config
        .get_embed_model_base_url()
        .map_err(|e| crate::AgentError::Internal(e.to_string()))?;
    let api_key = config
        .get_embed_model_api_key()
        .map_err(|e| crate::AgentError::Internal(e.to_string()))?;
    let qdrant_url = config
        .get_qdrant_url()
        .map_err(|e| crate::AgentError::Internal(e.to_string()))?;
    let qdrant_api_key = config.get_qdrant_api_key();

    let openai = rig::providers::openai::Client::builder()
        .api_key(&api_key)
        .base_url(&base_url)
        .build()
        .map_err(|e| crate::AgentError::Internal(format!("failed to build rig openai client: {}", e)))?;

    let qdrant = QdrantClient::new(&qdrant_url, qdrant_api_key.as_deref()).await?;
    Ok(EmbedClient::new(openai, qdrant))
}
