use serde_json::Value;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum WebsocketAdapterError {
    #[error("invalid websocket url: {url}")]
    InvalidUrl { url: String },
    #[error("invalid websocket header name {header}")]
    InvalidHeaderName { header: String },
    #[error("invalid websocket header value for {header}")]
    InvalidHeaderValue { header: String },
    #[error("invalid websocket subprotocol {value}")]
    InvalidSubprotocol { value: String },
    #[error("websocket connect failed")]
    Connect(#[from] tokio_tungstenite::tungstenite::Error),
    #[error("websocket window expired before collecting any items")]
    WindowExpired,
    #[error("websocket stream produced malformed frame payload")]
    InvalidFramePayload,
    #[error("websocket endpoint returned close frame before collection completed")]
    ClosedEarly,
    #[error("websocket reconnect policy exhausted")]
    ReconnectExhausted,
    #[error("websocket upstream returned invalid subscribe payload")]
    InvalidSubscribePayload,
    #[error("websocket upstream returned invalid unsubscribe payload")]
    InvalidUnsubscribePayload,
    #[error("websocket upstream status {status}")]
    UnexpectedStatus { status: u16, body: Value },
}
