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

use async_openai::config::OpenAIConfig;

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 = async_openai::Client::with_config(
        OpenAIConfig::new()
            .with_api_base(base_url)
            .with_api_key(api_key),
    );
    let qdrant = QdrantClient::new(&qdrant_url, qdrant_api_key.as_deref()).await?;
    Ok(EmbedClient::new(openai, qdrant))
}
