"""
Debug ChromaDB 0.3.29 API to understand the correct usage
"""

import chromadb
from chromadb.config import Settings

print("ChromaDB version:", chromadb.__version__)
print("\nTesting ChromaDB 0.3.29 API...")

# Create client
client = chromadb.Client(Settings(
    chroma_db_impl="duckdb+parquet",
    persist_directory=".mira/chromadb_debug"
))

print("\nClient methods:")
client_methods = [m for m in dir(client) if not m.startswith('_')]
print(client_methods)

# Test get_or_create_collection
print("\n\nTesting get_or_create_collection...")
try:
    result = client.get_or_create_collection("test_collection", metadata={"test": "value"})
    print(f"Result type: {type(result)}")
    print(f"Result: {result}")
    
    if result:
        print("\nCollection methods:")
        collection_methods = [m for m in dir(result) if not m.startswith('_')]
        print(collection_methods)
except Exception as e:
    print(f"Error: {e}")
    print(f"Error type: {type(e)}")

# Test create_collection directly
print("\n\nTesting create_collection...")
try:
    # First delete if exists
    try:
        client.delete_collection("test_create")
    except:
        pass
    
    result2 = client.create_collection("test_create", metadata={"test": "create"})
    print(f"Create result type: {type(result2)}")
    print(f"Create result: {result2}")
    
    if result2:
        # Test add method
        print("\nTesting add method...")
        result2.add(
            documents=["test document"],
            metadatas=[{"type": "test"}],
            ids=["test_1"]
        )
        print("✅ Add successful")
        
        # Test get
        docs = result2.get(ids=["test_1"])
        print(f"Retrieved: {docs}")
        
except Exception as e:
    print(f"Create error: {e}")
    print(f"Create error type: {type(e)}")

# Check if we need to use a different approach
print("\n\nChecking alternative approaches...")
try:
    # List collections to see format
    collections = client.list_collections()
    print(f"Collections type: {type(collections)}")
    print(f"Number of collections: {len(collections)}")
    if collections:
        print(f"First collection type: {type(collections[0])}")
        print(f"First collection: {collections[0]}")
except Exception as e:
    print(f"List error: {e}")

# Clean up
try:
    client.delete_collection("test_collection")
    client.delete_collection("test_create")
except:
    pass

print("\n✅ Debug complete")