import os
from . import chroma_store
from ..mongo import vector_store as mongo_store

def _use_atlas():
    return os.environ.get("ATLAS_VECTORS", "false").lower() == "true"

def get_chroma_client():
    # Only used by chroma-specific things if external
    return chroma_store.get_chroma_client()

def get_collection(collection_name=chroma_store.COLLECTION_NAME):
    if _use_atlas():
        return mongo_store.get_collection(collection_name)
    return chroma_store.get_collection(collection_name)

def insert_documents(texts, embeddings, collection_name=chroma_store.COLLECTION_NAME, metadata_list=None):
    if _use_atlas():
        return mongo_store.insert_documents(texts, embeddings, collection_name, metadata_list)
    return chroma_store.insert_documents(texts, embeddings, collection_name, metadata_list)

def search_documents(query_embedding, collection_name=chroma_store.COLLECTION_NAME, num_results=5, filter_metadata=None):
    if _use_atlas():
        return mongo_store.search_documents(query_embedding, collection_name, num_results, filter_metadata)
    return chroma_store.search_documents(query_embedding, collection_name, num_results, filter_metadata)

def delete_documents_by_source(source_file, collection_name=chroma_store.COLLECTION_NAME):
    if _use_atlas():
        return mongo_store.delete_documents_by_source(source_file, collection_name)
    return chroma_store.delete_documents_by_source(source_file, collection_name)

def get_all_metadatas(collection_name=chroma_store.COLLECTION_NAME, limit=None):
    if _use_atlas():
        return mongo_store.get_all_metadatas(collection_name, limit)
    return chroma_store.get_all_metadatas(collection_name, limit)
