//! Storage backend trait abstractions and implementations
//!
//! Defines the core traits for the mesh storage layer, enabling runtime
//! backend selection between various storage implementations.

pub mod traits;

// Pure-generic storage types (no feature gate)
pub mod blob_traits;
pub mod geohash_index;
pub mod streaming_transfer;
pub mod ttl;

// Automerge backend storage (ADR-049 Phase 3)
#[cfg(feature = "automerge-backend")]
pub mod automerge_store;
#[cfg(feature = "automerge-backend")]
pub mod cipher;
#[cfg(feature = "automerge-backend")]
pub mod flow_control;
#[cfg(feature = "automerge-backend")]
pub mod interface_filter;
// Provider gossip rides the iroh blob store, so it requires the same feature.
#[cfg(feature = "automerge-backend")]
pub mod blob_announce;
// Distribution / file-transfer implementation (relocated from peat-protocol per
// peat#992 — peat-mesh is the canonical iroh consumer; transport-specific impl
// belongs here, not in the protocol/spec layer).
#[cfg(feature = "automerge-backend")]
pub mod file_distribution;
#[cfg(feature = "automerge-backend")]
pub mod iroh_blob_store;
#[cfg(feature = "automerge-backend")]
pub mod json_convert;
#[cfg(feature = "automerge-backend")]
pub mod model_distribution;
#[cfg(feature = "automerge-backend")]
pub mod negentropy_sync;
#[cfg(feature = "automerge-backend")]
pub mod partition_detection;
#[cfg(feature = "automerge-backend")]
pub mod query;
#[cfg(feature = "automerge-backend")]
pub mod sync_errors;
#[cfg(feature = "automerge-backend")]
pub mod sync_persistence;
#[cfg(feature = "automerge-backend")]
pub mod ttl_manager;
#[cfg(feature = "automerge-backend")]
pub mod typed_collection;

// Certificate CRDT store and enrollment protocol
#[cfg(feature = "automerge-backend")]
pub mod certificate_store;
#[cfg(feature = "automerge-backend")]
pub mod enrollment_transport;

// Sync coordination (extracted from peat-mesh)
#[cfg(feature = "automerge-backend")]
pub mod automerge_sync;
#[cfg(feature = "automerge-backend")]
pub mod mesh_sync_transport;
#[cfg(feature = "automerge-backend")]
pub mod sync_channel;
#[cfg(feature = "automerge-backend")]
pub mod sync_forwarding;
#[cfg(feature = "automerge-backend")]
pub mod sync_transport;

// Re-export key types (ungated)
pub use blob_traits::{
    BlobHandle, BlobHash, BlobMetadata, BlobProgress, BlobStorageSummary, BlobStore, BlobStoreExt,
    BlobToken, SharedBlobStore,
};
pub use geohash_index::GeohashIndex;
pub use streaming_transfer::{StreamingTransferConfig, TransferCheckpoint, TransferResult};
pub use traits::{Collection, DocumentPredicate, StorageBackend};
pub use ttl::{EvictionStrategy, OfflineRetentionPolicy, TtlConfig};

// Re-export key types (feature-gated)
#[cfg(feature = "automerge-backend")]
pub use automerge_store::{AutomergeDelta, AutomergeStore, ChangeOrigin, DocChange};
#[cfg(feature = "automerge-backend")]
pub use cipher::Cipher;
#[cfg(feature = "automerge-backend")]
pub use flow_control::{
    BoundedQueue, FlowControlConfig, FlowControlError, FlowControlStats, FlowController,
    PeerResourceTracker, SyncCooldownTracker, TokenBucket,
};
#[cfg(feature = "automerge-backend")]
pub use iroh_blob_store::{BlobPeerIndex, IrohBlobStore, NetworkedIrohBlobStore};
// Distribution / file-transfer API (relocated from peat-protocol per peat#992).
#[cfg(feature = "automerge-backend")]
pub use file_distribution::{
    clear_receive_test_directives, read_distribution_document, scan_distribution_document_ids,
    scan_distribution_documents, set_receive_test_directive, write_receiver_node_status,
    CollectionSubscriptionNeed, DistributionDocument, DistributionHandle, DistributionScope,
    DistributionStatus, FileDistribution, IrohFileDistribution, NeedEvaluator, NodeTransferStatus,
    ReceiveSink, ReceiveTestDirective, TransferPriority, TransferState,
    IROH_DISTRIBUTION_COLLECTION,
};
#[cfg(feature = "automerge-backend")]
pub use model_distribution::{
    BlockerReason, ConvergenceBlocker, ModelConvergenceStatus, ModelDeploymentTracker,
    ModelDistribution, ModelDistributionHandle, ModelOperationalStatus, NodeModelStatus,
    VariantSelector,
};
#[cfg(feature = "automerge-backend")]
pub use negentropy_sync::{NegentropyStats, NegentropySync, ReconcileResult, SyncItem};
#[cfg(feature = "automerge-backend")]
pub use partition_detection::{
    PartitionConfig, PartitionDetector, PartitionEvent, PeerHeartbeat, PeerPartitionState,
};
#[cfg(feature = "automerge-backend")]
pub use query::{extract_field, Query, SortOrder, Value};
#[cfg(feature = "automerge-backend")]
pub use sync_persistence::{
    Checkpoint, PersistedSyncState, PersistenceStats, SyncStatePersistence,
};
#[cfg(feature = "automerge-backend")]
pub use ttl_manager::TtlManager;
#[cfg(feature = "automerge-backend")]
pub use typed_collection::TypedCollection;

// Certificate store re-exports
#[cfg(feature = "automerge-backend")]
pub use certificate_store::{CertificateEntry, CertificateStore, RevocationEntry};

// Enrollment re-exports
#[cfg(feature = "automerge-backend")]
pub use enrollment_transport::{
    request_enrollment, EnrollmentProtocolHandler, CAP_ENROLLMENT_ALPN,
};

// Sync coordination re-exports
#[cfg(feature = "automerge-backend")]
pub use automerge_sync::{
    AutomergeSyncCoordinator, PeerSyncStats, ReceivedSyncPayload, SyncBatch, SyncDirection,
    SyncEntry, SyncMessageType, DEFAULT_SYNC_BATCH_TTL,
};
#[cfg(feature = "automerge-backend")]
pub use iroh_blob_store::FormationEndpointHooks;
#[cfg(feature = "automerge-backend")]
pub use mesh_sync_transport::{
    respond_to_formation_auth, InboundPeerRegistry, MeshSyncTransport, SyncProtocolHandler,
};

// Re-export iroh multipath and endpoint types for downstream use
#[cfg(feature = "automerge-backend")]
pub mod iroh_types {
    //! Re-exported iroh types for multipath connection info and endpoint hooks.
    //!
    //! iroh 1.0.0-rc.0 renamed the multipath surface: `PathInfo` → `Path<'a>`
    //! (borrows from the parent `PathList`), and `PathWatcher` was retired in
    //! favor of `PathListStream` (a `Stream<Item = PathList<'_>>` returned by
    //! `Connection::paths_stream()`). Consumers that previously held a
    //! long-lived `PathWatcher` now drive a `PathListStream::next()` loop and
    //! reach owned snapshots via `PathStats` (the per-path stats type from
    //! noq-proto that iroh re-exports).
    pub use iroh::endpoint::{
        Connection, EndpointHooks, Path, PathEvent, PathEventStream, PathId, PathList,
        PathListStream, PathStats,
    };
    pub use iroh::Watcher;
}
#[cfg(feature = "automerge-backend")]
pub use sync_channel::{ChannelManagerStats, ChannelState, SyncChannel, SyncChannelManager};
#[cfg(feature = "automerge-backend")]
pub use sync_forwarding::{ForwardingStats, SyncForwarder};
#[cfg(feature = "automerge-backend")]
pub use sync_transport::{SyncRouter, SyncTransport, CAP_AUTOMERGE_ALPN};
