//! WebSocket transport for real-time credential verification status updates.
//!
//! This module provides WebSocket-based transport for receiving instant
//! status updates from the IDP when credential verification completes.
//! Falls back to HTTP polling if WebSocket connection fails.
//!
//! # Platform Support
//!
//! - **Native**: Uses `tokio-tungstenite` for WebSocket connections
//! - **WASM**: Uses browser's native `WebSocket` API via `web-sys`

mod messages;
mod subscription;
mod transport;

#[cfg(not(target_arch = "wasm32"))]
mod native;

#[cfg(target_arch = "wasm32")]
mod wasm;

pub use messages::{StatusUpdate, VerificationStatusPayload, WsMessage};
#[cfg(not(target_arch = "wasm32"))]
pub use native::NativeWebSocket;
pub use subscription::StatusSubscription;
pub use transport::WebSocketTransport;
#[cfg(target_arch = "wasm32")]
pub use wasm::WasmWebSocket;

use crate::config::WebSocketConfig;
use crate::error::WebSocketError;
use crate::types::RequestId;

/// Create a platform-specific WebSocket transport.
#[cfg(not(target_arch = "wasm32"))]
pub fn create_transport(
    base_url: &str,
    request_id: &RequestId,
    config: &WebSocketConfig,
) -> Result<NativeWebSocket, WebSocketError> {
    NativeWebSocket::new(base_url, request_id, config)
}

/// Create a platform-specific WebSocket transport.
#[cfg(target_arch = "wasm32")]
pub fn create_transport(
    base_url: &str,
    request_id: &RequestId,
    config: &WebSocketConfig,
) -> Result<WasmWebSocket, WebSocketError> {
    WasmWebSocket::new(base_url, request_id, config)
}
