//! Synor IBC - Inter-Blockchain Communication Protocol
//!
//! This crate implements the IBC protocol for cross-chain communication,
//! enabling Synor to interoperate with Cosmos SDK chains and other IBC-compatible blockchains.
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │                    Synor Blockchain                          │
//! ├─────────────────────────────────────────────────────────────┤
//! │  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐  │
//! │  │ IBC Client  │  │ Connection  │  │      Channel        │  │
//! │  │  (Light     │  │  (Verified  │  │  (Ordered/Unordered │  │
//! │  │   Client)   │  │   Link)     │  │   Message Passing)  │  │
//! │  └──────┬──────┘  └──────┬──────┘  └──────────┬──────────┘  │
//! │         │                │                     │             │
//! │         └────────────────┼─────────────────────┘             │
//! │                          │                                   │
//! │                    ┌─────┴─────┐                             │
//! │                    │  Packet   │                             │
//! │                    │  Handler  │                             │
//! │                    └─────┬─────┘                             │
//! └──────────────────────────┼──────────────────────────────────┘
//!                            │
//!                      ┌─────┴─────┐
//!                      │  Relayer  │
//!                      └─────┬─────┘
//!                            │
//! ┌──────────────────────────┼──────────────────────────────────┐
//! │                    Remote Chain                              │
//! └─────────────────────────────────────────────────────────────┘
//! ```
//!
//! # IBC Handshake Flow
//!
//! ## Connection Handshake (4-way)
//! 1. `ConnOpenInit` - Chain A initiates
//! 2. `ConnOpenTry` - Chain B responds
//! 3. `ConnOpenAck` - Chain A acknowledges
//! 4. `ConnOpenConfirm` - Chain B confirms
//!
//! ## Channel Handshake (4-way)
//! 1. `ChanOpenInit` - Chain A initiates
//! 2. `ChanOpenTry` - Chain B responds
//! 3. `ChanOpenAck` - Chain A acknowledges
//! 4. `ChanOpenConfirm` - Chain B confirms
//!
//! # Example
//!
//! ```ignore
//! use synor_ibc::{IbcHandler, ConnectionId, ChannelId};
//!
//! // Initialize IBC handler
//! let handler = IbcHandler::new(config);
//!
//! // Create a connection to a remote chain
//! let conn_id = handler.connection_open_init(
//!     client_id,
//!     counterparty,
//!     version,
//! ).await?;
//!
//! // Open a channel for token transfers
//! let channel_id = handler.channel_open_init(
//!     port_id,
//!     conn_id,
//!     counterparty_port,
//!     version,
//! ).await?;
//!
//! // Send a packet
//! handler.send_packet(
//!     channel_id,
//!     data,
//!     timeout,
//! ).await?;
//! ```

pub mod client;
pub mod connection;
pub mod channel;
pub mod packet;
pub mod commitment;
pub mod error;
pub mod handler;
pub mod swap;
pub mod types;

pub use client::{ClientState, ConsensusState, LightClient};
pub use connection::{ConnectionEnd, ConnectionState, ConnectionId, Counterparty};
pub use channel::{Channel, ChannelState, ChannelId, PortId, ChannelOrder};
pub use packet::{Packet, PacketCommitment, Acknowledgement, Timeout};
pub use commitment::{CommitmentProof, MerkleProof, MerklePath};
pub use error::{IbcError, IbcResult};
pub use handler::IbcHandler;
pub use swap::{AtomicSwap, Htlc, SwapManager, SwapId, SwapState, SwapAsset, Hashlock, Timelock};
pub use types::*;

/// IBC protocol version
pub const IBC_VERSION: &str = "1";

/// Default packet timeout in blocks
pub const DEFAULT_TIMEOUT_HEIGHT: u64 = 1000;

/// Default packet timeout in nanoseconds (1 hour)
pub const DEFAULT_TIMEOUT_TIMESTAMP: u64 = 3_600_000_000_000;

/// Maximum packet data size (1 MB)
pub const MAX_PACKET_DATA_SIZE: usize = 1024 * 1024;

/// Connection prefix for Synor
pub const SYNOR_CONNECTION_PREFIX: &str = "synor";

/// Well-known port for token transfers
pub const TRANSFER_PORT: &str = "transfer";

/// Well-known port for interchain accounts
pub const ICA_PORT: &str = "icahost";

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

    #[test]
    fn test_constants() {
        assert_eq!(IBC_VERSION, "1");
        assert!(DEFAULT_TIMEOUT_HEIGHT > 0);
        assert!(DEFAULT_TIMEOUT_TIMESTAMP > 0);
        assert!(MAX_PACKET_DATA_SIZE > 0);
    }
}
