"""
SQLCipher compatibility module for cross-platform support.

Provides a unified interface for importing SQLCipher on different platforms:
- x86_64: Uses sqlcipher3-binary
- ARM64: Uses pysqlcipher3
"""


def get_sqlcipher_module():
    """
    Get the appropriate SQLCipher module for the current platform.

    Returns the sqlcipher3 module on x86_64 or pysqlcipher3 on ARM64.
    For compatibility, both modules are wrapped to have the same API.

    Returns:
        module: The sqlcipher module with dbapi2 attribute

    Raises:
        ImportError: If neither sqlcipher3 nor pysqlcipher3 is available
    """
    try:
        import sqlcipher3

        return sqlcipher3
    except ImportError:
        try:
            # pysqlcipher3 has a different API structure
            # We need to import dbapi2 directly and wrap it
            from pysqlcipher3 import dbapi2
            from types import SimpleNamespace

            # Create a wrapper that has the same API as sqlcipher3
            # Using SimpleNamespace to wrap the dbapi2 submodule
            return SimpleNamespace(dbapi2=dbapi2)
        except ImportError:
            raise ImportError(
                "Neither sqlcipher3 nor pysqlcipher3 is installed. "
                "Install with: pip install sqlcipher3-binary (x86_64) or pip install pysqlcipher3 (ARM64)"
            )
