use crate::discovery::ServiceInstance;
use crate::discovery_etcd::{EtcdDiscoveryError, EtcdDiscoveryResult};

pub(crate) fn validate_instance(instance: &ServiceInstance) -> EtcdDiscoveryResult<()> {
    validate_name("service", &instance.service)?;
    validate_name("id", &instance.id)
}

pub(crate) fn validate_name(label: &str, value: &str) -> EtcdDiscoveryResult<()> {
    if value.trim_matches('/').trim().is_empty() {
        return Err(EtcdDiscoveryError::InvalidConfig(format!(
            "{label} must not be empty"
        )));
    }
    Ok(())
}
