"""
Mongoengine Read-Write Router

A MongoDB read-write separation solution for mongoengine ODM, inspired by
django-rw-router architecture. Routes write operations to primary database
and read operations to replica set members, with configurable consistency
strategies.

Example usage:
    from mongoengine import connect, Document, StringField, IntField
    from mongoengine_rw_router import (
        RwDocumentMixin,
        configure,
        MongoRouterMiddleware,
    )

    # Configure connections
    connect(db="mydb", alias="default", host="mongodb://primary:27017")
    connect(
        db="mydb",
        alias="replica1",
        host="mongodb://replica1:27017",
        read_preference=ReadPreference.SECONDARY_PREFERRED,
    )

    # Configure router
    configure(
        primary_alias="default",
        replica_aliases=["replica1"],
        strategy="transaction_aware",
    )

    # Define model with routing
    class User(RwDocumentMixin, Document):
        name = StringField()
        age = IntField()

        meta = {"db_alias": "default"}

    # FastAPI integration
    from fastapi import FastAPI
    app = FastAPI()
    app.add_middleware(MongoRouterMiddleware)
"""

from .config import (
    MongoRouterConfig,
    configure,
    configure_from_hosts,
    configure_from_url,
    get_config,
    set_config,
)
from .connections import (
    MongoConnectionManager,
    force_primary,
    get_connection_manager,
    get_read_db_alias,
    get_write_db_alias,
)
from .context import (
    RequestContext,
    get_request_id,
    get_user_id,
    has_write_operations,
    is_in_transaction,
)
from .document import RwDocumentMixin, RwManager
from .middleware import (
    DJANGO_AVAILABLE,
    FASTAPI_AVAILABLE,
    FLASK_AVAILABLE,
    MongoRouterDjangoMiddleware,
    MongoRouterFlaskMiddleware,
    MongoRouterMiddleware,
    get_middleware,
)
from .queryset import RwQuerySet

__version__ = "0.0.3"

__all__ = [
    # Version
    "__version__",
    # Configuration
    "MongoRouterConfig",
    "configure",
    "configure_from_url",
    "configure_from_hosts",
    "get_config",
    "set_config",
    # Connections
    "MongoConnectionManager",
    "force_primary",
    "get_connection_manager",
    "get_read_db_alias",
    "get_write_db_alias",
    # Context
    "RequestContext",
    "get_user_id",
    "get_request_id",
    "has_write_operations",
    "is_in_transaction",
    # Document
    "RwDocumentMixin",
    "RwManager",
    # QuerySet
    "RwQuerySet",
    # Middleware
    "MongoRouterMiddleware",
    "MongoRouterFlaskMiddleware",
    "MongoRouterDjangoMiddleware",
    "get_middleware",
    "FASTAPI_AVAILABLE",
    "FLASK_AVAILABLE",
    "DJANGO_AVAILABLE",
]
