use std::collections::{HashMap, HashSet};
use cedar_policy::{Context, Entity, EntityUid, RestrictedExpression};
use crate::error::PolicyError;
pub trait CedarAtom {
fn cedar_type() -> &'static str;
fn cedar_parents(&self) -> HashSet<EntityUid> {
HashSet::new()
}
fn cedar_entity(&self) -> Result<Entity, PolicyError> {
let entity_uid = self.cedar_entity_uid()?;
let attrs = self.cedar_attr()?;
Ok(Entity::new(entity_uid, attrs, self.cedar_parents())?)
}
fn cedar_attr(&self) -> Result<HashMap<String, RestrictedExpression>, PolicyError> {
let res: HashMap<String, RestrictedExpression> = HashMap::new();
Ok(res)
}
fn cedar_entity_uid(&self) -> Result<EntityUid, PolicyError> {
self.cedar_id()
.parse::<EntityUid>()
.map_err(|e| PolicyError::ParseError(e.to_string()))
}
fn cedar_ctx(&self) -> Result<Context, PolicyError> {
Ok(Context::empty())
}
fn cedar_id(&self) -> String;
}