//! Environment variables that serde can handle.

use std::collections::HashMap;

use serde::{Deserialize, Serialize};

/// Represent environment variables in a way that serde can handle,
/// and can be stored in the runnable plan and the action context.
///
/// Constraints:
/// * keys are strings
/// * values are byte vectors
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct EnvVars {
    map: HashMap<String, Vec<u8>>,
}

impl EnvVars {
    /// Set an environment variable.
    pub fn set(&mut self, name: impl Into<String>, value: impl Into<Vec<u8>>) {
        self.map.insert(name.into(), value.into());
    }

    /// Iterate over names and values.
    pub fn iter(&self) -> impl Iterator<Item = (&String, &Vec<u8>)> {
        self.map.iter()
    }
}
