use std::collections::HashMap;

/// The format table for `key=value` pairs used when rendering `Arguments`, like in `format()`
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct FormatTable {
    table: HashMap<String, String>,
}

impl FormatTable {
    /// Creates a new, empty format table
    pub fn new() -> Self {
        Self {
            table: HashMap::new(),
        }
    }

    /// Adds a single `key=value` pair to the table
    pub fn add_entry(&mut self, key: impl Into<String>, value: impl Into<String>) {
        self.table
            .insert(key.into().to_ascii_lowercase(), value.into());
    }

    /// Extends the table with an iterator of `key=value` pairs
    pub fn add_table(&mut self, table: impl IntoIterator<Item = (String, String)>) {
        self.table.extend(table);
    }

    /// Gets the the held table of `self`
    pub fn table(&self) -> &HashMap<String, String> {
        &self.table
    }
}
