use iref::Iri;
use json::JsonValue;
use crate::{
Error,
Id,
object::*,
ContextMut,
context::{
Loader,
TermDefinition
},
syntax::ContainerType
};
use super::{
Options,
Expanded,
expand_element
};
pub async fn expand_array<T: Send + Sync + Id, C: Send + Sync + ContextMut<T>, L: Send + Sync + Loader>(active_context: &C, active_property: Option<&str>, active_property_definition: Option<&TermDefinition<T, C>>, element: &[JsonValue], base_url: Option<Iri<'_>>, loader: &mut L, options: Options) -> Result<Expanded<T>, Error> where C::LocalContext: Send + Sync + From<L::Output> + From<JsonValue>, L::Output: Into<JsonValue> {
let mut is_list = false;
let mut result = Vec::new();
if let Some(definition) = active_property_definition {
is_list = definition.container.contains(ContainerType::List);
}
for item in element {
result.extend(expand_element(active_context, active_property, item, base_url, loader, options).await?);
}
if is_list {
return Ok(Expanded::Object(Object::List(result).into()))
}
return Ok(Expanded::Array(result))
}