use std::collections::HashMap;

use super::dynamic_state::{vato007::ingey::types::HostReadMap, DynamicState};

pub struct ReadMapData {
    pub data: HashMap<String, String>,
}

impl HostReadMap for DynamicState {
    fn get(
        &mut self,
        self_: wasmtime::component::Resource<ReadMapData>,
        key: String,
    ) -> Option<String> {
        self.resources
            .get(&self_)
            .ok()
            .map(|data| data.data.get(&key).cloned())
            .flatten()
    }

    fn drop(&mut self, rep: wasmtime::component::Resource<ReadMapData>) -> wasmtime::Result<()> {
        self.resources.delete(rep)?;
        Ok(())
    }
}
