use std::collections::BTreeMap;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct ResourceRef {
pub kind: String,
pub resource_id: Option<String>,
pub tenant_id: Option<String>,
pub owner_id: Option<String>,
pub attributes: BTreeMap<String, String>,
}
impl ResourceRef {
pub fn new(kind: impl Into<String>) -> Self {
Self {
kind: kind.into(),
..Default::default()
}
}
pub fn with_tenant(mut self, tenant_id: impl Into<String>) -> Self {
self.tenant_id = Some(tenant_id.into());
self
}
pub fn with_owner(mut self, owner_id: impl Into<String>) -> Self {
self.owner_id = Some(owner_id.into());
self
}
pub fn with_id(mut self, resource_id: impl Into<String>) -> Self {
self.resource_id = Some(resource_id.into());
self
}
pub fn with_attribute(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.attributes.insert(key.into(), value.into());
self
}
#[must_use]
pub fn attr(&self, key: &str) -> Option<&str> {
self.attributes.get(key).map(String::as_str)
}
}