//! P2P transport built on iroh's QUIC endpoint.
//!
//! This module hosts the canonical `IrohTransport` for the peat ecosystem.
//! Per ADR-062, it moved here from peat-protocol so that peat-mesh owns the
//! full Automerge-over-iroh sync path end-to-end without round-tripping
//! through the higher-level protocol crate. peat-protocol now re-exports
//! these types for backwards compatibility.

#[cfg(feature = "automerge-backend")]
pub mod iroh_transport;

#[cfg(feature = "automerge-backend")]
pub mod peer_info;

#[cfg(feature = "automerge-backend")]
pub mod quic_mesh_connection;

#[cfg(feature = "automerge-backend")]
pub use iroh_transport::{
    IrohTransport, TransportEventReceiver, TransportEventSender, TransportPeerEvent,
    CAP_AUTOMERGE_ALPN,
};
#[cfg(feature = "automerge-backend")]
pub use peer_info::PeerInfo;
#[cfg(feature = "automerge-backend")]
pub use quic_mesh_connection::QuicMeshConnection;

// ADR-062 Phase 2 (peat#926) — re-exports so consumers don't need
// direct `use iroh::` / `use iroh_mdns_address_lookup::` lines.
// Lets peat-protocol's post-Phase-2 code reference these types via
// peat-mesh paths, satisfying the SKILL.md transport-agnosticism gate
// and allowing peat-protocol/Cargo.toml to drop `iroh` and
// `iroh-mdns-address-lookup` from its direct-deps section.
//
// `EndpointId` shipped in rc.21 with the Phase 2 surface; `Connection`
// and `DiscoveryEvent` are added in rc.22 to cover the remaining
// peat-protocol consumers (formation_handshake.rs and sync/automerge.rs
// respectively) that the original Phase 2 surface accidentally missed.
//
// **peat-mesh#167 (rc.24)**: `Connection` is no longer re-exported
// here — peat-protocol's `formation_handshake.rs` (the sole prior
// consumer) now takes `&dyn QuicMeshConnection` instead of the raw
// iroh handle. The trait narrows the surface from "any iroh
// `Connection` method" to the four methods the handshake actually
// uses (`open_bi`, `accept_bi`, `close_reason`, `remote_endpoint_id`).
// `SendStream`, `RecvStream`, and `ConnectionError` are re-exported
// below because the trait's method signatures reference them;
// downstream consumers can name them without reaching for
// `use iroh::endpoint::*`. `remote_endpoint_id` returns infallible
// `EndpointId` (matches `iroh::endpoint::Connection::remote_id` on the
// default non-0-RTT shape), so no error type is re-exported for it.
#[cfg(feature = "automerge-backend")]
pub use iroh::endpoint::{ConnectionError, RecvStream, SendStream};
#[cfg(feature = "automerge-backend")]
pub use iroh::EndpointId;
#[cfg(feature = "automerge-backend")]
pub use iroh_mdns_address_lookup::DiscoveryEvent;

#[cfg(all(test, feature = "automerge-backend"))]
mod reexport_pin {
    // Structural pin for the upstream re-export paths. A future iroh /
    // iroh-mdns-address-lookup rename or path-refactor would break this
    // compile, catching the regression at peat-mesh's CI before a
    // downstream peat-protocol build hits it. Per the QA review of
    // peat-mesh#166: pure type re-exports have no behavior to
    // round-trip, so a compile-only typecheck is the right shape.
    //
    // Gated on `cfg(all(test, feature = "automerge-backend"))` — fires
    // only when BOTH `test` and the `automerge-backend` feature are
    // active. peat-mesh's CI exercises this via the `clippy` job
    // (`.github/workflows/ci.yml:40`: `cargo clippy --all-targets
    // --features automerge-backend -- -D warnings`); the `test` job
    // (`ci.yml:49`: bare `cargo test`) does NOT fire the pin because it
    // doesn't activate the feature. Clippy alone suffices for the
    // rename-detection guarantee — adding `--features automerge-backend`
    // to `cargo test` would be belt-and-suspenders but isn't required.
    #[allow(dead_code)]
    fn _typecheck(
        _e: super::EndpointId,
        _d: super::DiscoveryEvent,
        _c: super::ConnectionError,
        _r: super::RecvStream,
        _s: super::SendStream,
    ) {
    }
}
