use thiserror::Error;

/// Result type used by service discovery operations.
pub type DiscoveryResult<T> = Result<T, DiscoveryError>;

/// Errors returned by discovery adapters and selectors.
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum DiscoveryError {
    /// A service has no available instances.
    #[error("service `{service}` has no available instances")]
    NoInstances { service: String },

    /// An instance cannot be registered because the id already exists.
    #[error("service `{service}` already has instance `{id}`")]
    DuplicateInstance { service: String, id: String },

    /// The requested instance does not exist.
    #[error("service `{service}` does not have instance `{id}`")]
    MissingInstance { service: String, id: String },

    /// A DNS lookup failed.
    #[error("failed to resolve `{host}`: {message}")]
    Resolve { host: String, message: String },

    /// The provided endpoint is invalid.
    #[error("invalid endpoint `{endpoint}`")]
    InvalidEndpoint { endpoint: String },
}
