use thiserror::Error;

/// Errors produced by the `CollabRemote` trait and its implementations.
#[derive(Debug, Error)]
pub enum CollabError {
    /// The caller's public key is not a member of the specified team.
    #[error("not a member of team {team_id}")]
    NotMember { team_id: String },

    /// The invite token was not found or has expired.
    #[error("invite not found or expired")]
    InviteNotFound,

    /// The public key presented during invite confirmation does not match the
    /// key the invite was originally bound to.
    #[error("pubkey mismatch in invite confirmation")]
    PubkeyMismatch,

    /// The remote server returned an unexpected HTTP status.
    #[error("http error {status}: {body}")]
    Http { status: u16, body: String },

    /// JSON serialization or deserialization failed.
    #[error("serialization error: {0}")]
    Serde(#[from] serde_json::Error),

    /// The remote server could not be reached (network / DNS / TLS failure).
    #[error("server unreachable: {0}")]
    Unreachable(String),

    /// A Shamir share could not be reconstructed into a valid 32-byte key.
    #[error("recovery key reconstruction failed: {0}")]
    RecoveryFailed(String),
}
