///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    #[error("TLS error: {0}")]
    Tls(#[from] native_tls::Error),

    #[error("protobuf encode error: {0}")]
    Encode(#[from] prost::EncodeError),

    #[error("protobuf decode error: {0}")]
    Decode(#[from] prost::DecodeError),

    #[error("cTrader API error [{error_code}]: {description}")]
    Api {
        error_code: String,
        description: String,
    },

    #[error("unexpected response payload type: {0}")]
    UnexpectedPayload(u32),

    #[error("request timed out")]
    Timeout,

    #[error("channel closed — client disconnected")]
    Disconnected,

    #[error("unknown payload type: {0}")]
    UnknownPayloadType(u32),
}
