"""
Information Spaces package for MarkiTect.

This package provides the Information Space abstraction, enabling:
- First-class space entities with identity, metadata, and lifecycle
- Event-driven change tracking and notifications
- Persistent transclusion context with cross-space references
- HTML rendering with caching and theme support
- Bidirectional directory synchronization
- Composable space hierarchies

Package Structure:
    - models: Core domain models (InformationSpace, SpaceDocument, SpaceConfig)
    - events: Event system (SpaceEvent, EventBus, handlers)
    - repositories: Data access layer (ISpaceRepository, SqliteSpaceRepository)
    - transclusion: Persistent transclusion context and reference tracking
    - rendering: Space rendering (HTML, themes)
    - sync: Directory synchronization (export, import, bidirectional)
    - services: Business logic (SpaceService)
    - history: Optional git-based version control

Usage:
    from markitect.spaces import SpaceService, InformationSpace

    service = SpaceService()
    space = await service.create_space("my-docs")
    await service.add_document(space, "/intro.md", content="# Intro")
    await service.render(space, output_dir="./html/")
"""

# Phase 1: Foundation
from .models import (
    InformationSpace,
    SpaceDocument,
    SpaceConfig,
    SpaceMetadata,
    SpaceVariable,
    TransclusionReference,
    SpaceStatus,
)
from .services import SpaceService
from .repositories import (
    ISpaceRepository,
    IDocumentAssociationRepository,
    IVariableRepository,
    IReferenceRepository,
    SqliteSpaceRepository,
    SqliteDocumentRepository,
    SqliteVariableRepository,
    SqliteReferenceRepository,
    initialize_space_tables,
)

# Phase 2: Event System
from .events import (
    SpaceEvent,
    SpaceEventType,
    EventBus,
    get_event_bus,
    reset_event_bus,
)

# Phase 7: Composability
from .composability import (
    # Models
    SpaceReference,
    SpaceReferenceType,
    SpacePermission,
    SpaceRole,
    AccessLevel,
    SpaceAccess,
    InheritedVariable,
    InheritedConfig,
    # Services
    ComposableSpaceService,
    InheritanceResolver,
    AccessControlService,
    # Repositories
    ISpaceReferenceRepository,
    IAccessControlRepository,
    SqliteSpaceReferenceRepository,
    SqliteAccessControlRepository,
)
from .composability.service import CircularReferenceError

# Phase 8: History Tracking (Optional)
from .history import (
    # Models
    Commit,
    Branch,
    HistoryEntry,
    DiffResult,
    DiffLine,
    DiffType,
    HistoryConfig,
    # Interfaces
    IHistoryBackend,
    IHistoryQuery,
    # Implementations
    GitHistoryBackend,
    GitError,
    GitHistoryEventHandler,
    HistoryEventCoordinator,
    HistoryQueryService,
)

__all__ = [
    # Models
    "InformationSpace",
    "SpaceDocument",
    "SpaceConfig",
    "SpaceMetadata",
    "SpaceVariable",
    "TransclusionReference",
    "SpaceStatus",
    # Services
    "SpaceService",
    # Repository Interfaces
    "ISpaceRepository",
    "IDocumentAssociationRepository",
    "IVariableRepository",
    "IReferenceRepository",
    # SQLite Implementations
    "SqliteSpaceRepository",
    "SqliteDocumentRepository",
    "SqliteVariableRepository",
    "SqliteReferenceRepository",
    "initialize_space_tables",
    # Event System
    "SpaceEvent",
    "SpaceEventType",
    "EventBus",
    "get_event_bus",
    "reset_event_bus",
    # Composability - Models
    "SpaceReference",
    "SpaceReferenceType",
    "SpacePermission",
    "SpaceRole",
    "AccessLevel",
    "SpaceAccess",
    "InheritedVariable",
    "InheritedConfig",
    # Composability - Services
    "ComposableSpaceService",
    "InheritanceResolver",
    "AccessControlService",
    "CircularReferenceError",
    # Composability - Repositories
    "ISpaceReferenceRepository",
    "IAccessControlRepository",
    "SqliteSpaceReferenceRepository",
    "SqliteAccessControlRepository",
    # History - Models
    "Commit",
    "Branch",
    "HistoryEntry",
    "DiffResult",
    "DiffLine",
    "DiffType",
    "HistoryConfig",
    # History - Interfaces
    "IHistoryBackend",
    "IHistoryQuery",
    # History - Implementations
    "GitHistoryBackend",
    "GitError",
    "GitHistoryEventHandler",
    "HistoryEventCoordinator",
    "HistoryQueryService",
]
