#[derive(Debug, PartialEq, Eq)]
/// Errors that can occur when parsing environment variables.
pub enum EnvError {
    /// An environment variable was found, but its value was invalid.
    Invalid { key: String, value: String, message: String },

    /// An environment variable was expected, but it was not found.
    MissingVar(String),
}

impl EnvError {
    /// Creates a new `EnvError::Invalid` with the given key, value, and message.
    pub fn invalid<K, V, M>(key: K, value: V, message: M) -> Self
    where
        K: Into<String>,
        V: Into<String>,
        M: Into<String>,
    {
        Self::Invalid {
            key: key.into(),
            value: value.into(),
            message: message.into(),
        }
    }

    /// Creates a new `EnvError::MissingVar` with the given key.
    pub fn missing<T>(key: T) -> Self
    where T: Into<String> {
        Self::MissingVar(key.into())
    }
}
