//! Data Synchronization Abstraction Layer
//!
//! This module provides a unified interface for CRDT-based data synchronization,
//! enabling Peat Protocol to work with multiple sync engines without changing
//! business logic.
//!
//! ## Architecture
//!
//! The abstraction consists of four core traits:
//!
//! 1. **`DocumentStore`** - CRUD operations, queries, and live observers
//! 2. **`PeerDiscovery`** - Finding and connecting to other nodes
//! 3. **`SyncEngine`** - Controlling synchronization behavior
//! 4. **`DataSyncBackend`** - Lifecycle management and trait composition
//!
//! ## Supported Backends
//!
//! - **Automerge + Iroh** - Open-source CRDT with QUIC-based P2P transport
//!
//! ## Usage Example
//!
//! ```rust,ignore
//! use peat_protocol::sync::{DataSyncBackend, BackendConfig};
//! use peat_protocol::storage::AutomergeBackend;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // Create backend
//! let backend = AutomergeBackend::new();
//!
//! // Initialize with config
//! let config = BackendConfig {
//!     app_id: "my-app".to_string(),
//!     persistence_dir: "/tmp/data".into(),
//!     // ...
//! };
//! backend.initialize(config).await?;
//!
//! // Start peer discovery and sync
//! backend.peer_discovery().start().await?;
//! backend.sync_engine().start_sync().await?;
//!
//! // Use document store
//! let doc_store = backend.document_store();
//! let doc = Document::new(fields);
//! doc_store.upsert("collection", doc).await?;
//!
//! // Cleanup
//! backend.shutdown().await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Testing
//!
//! The abstraction enables testing without real backends:
//!
//! ```rust,ignore
//! use peat_protocol::sync::mock::MockBackend;
//!
//! # async fn test_example() {
//! let backend = MockBackend::new();
//! // Test Peat protocol logic with mock backend
//! # }
//! ```
//!
//! ## Design Rationale
//!
//! See ADR-005 for full context on why this abstraction exists:
//! - Eliminate vendor lock-in with proprietary sync engines
//! - Enable open-source alternatives for DoD/NATO deployments
//! - Support multiple sync strategies (Ditto, Automerge, custom)
//! - Simplify testing (mocks, no real Ditto instances needed)

pub mod traits;
pub mod types;

// Backend implementations
#[cfg(feature = "automerge-backend")]
pub mod automerge; // Automerge CRDT backend (E8 evaluation)

// In-flight origin map for IrohDocumentStore observer-pipeline origin
// threading (ADR-059 §"Origin propagation through async observer pipelines").
#[cfg(feature = "automerge-backend")]
pub(crate) mod pending_origins;

// BLE translation layer (ADR-041, #557). The translator implements
// `peat_mesh::transport::Translator` (ADR-059 Slice 1.b.2) so it plugs
// directly into `TransportManager`'s fan-out — the older `BleGateway`
// wrapper that composed translator+Node has been deleted (Slice 1.b.2.2);
// callers compose the two themselves at their own integration boundary.
#[cfg(feature = "bluetooth")]
pub mod ble_translation;

// Re-export core types and traits for convenience
pub use traits::*;
pub use types::*;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_module_compiles() {
        // Sanity check that all types and traits are accessible
        let _: Option<Document> = None;
        let _: Option<Query> = None;
        let _: Option<BackendConfig> = None;
    }
}
