use super::business::{spec, BusinessNode, Kind::Amount, Kind::Text, TagSpec};
use super::element::{attributes, elements};
use super::Json;
elements! {
address = "Address": leaf;
listing = "Listing": leaf;
stock = "Stock": leaf;
owner = "Owner": leaf;
}
attributes! {
pub trait ProfileAttrs {
website; line1; line2; city; region; postal; country; authorized; reserved; par; percent; venue; symbol;
}
}
pub(crate) const PROFILE_COMPANY_PROPS: &[&str] = &["website"];
pub(crate) const PROFILE_TAGS: &[TagSpec] = &[
spec(
"Address",
&[("kind", Text), ("line1", Text), ("line2", Text), ("city", Text), ("region", Text), ("postal", Text), ("country", Text), ("source", Text)],
&["kind", "line1", "country"],
),
spec("Listing", &[("venue", Text), ("symbol", Text), ("since", Text), ("source", Text)], &["venue", "symbol"]),
spec("Stock", &[("kind", Text), ("authorized", Amount), ("issued", Amount), ("reserved", Amount), ("par", Text), ("source", Text)], &["kind", "authorized"]),
spec("Owner", &[("name", Text), ("holder", Text), ("percent", Amount), ("since", Text), ("source", Text)], &["name", "percent"]),
];
pub(crate) const PROFILE_LISTS: &[(&str, &str)] = &[("addresses", "Address"), ("listings", "Listing"), ("stock", "Stock"), ("owners", "Owner")];
pub(crate) fn profile_of(node: &BusinessNode, company: Json) -> Json {
let mut company = company;
for k in PROFILE_COMPANY_PROPS {
if let Some(v) = node.prop(k) {
company = company.with(k, v.clone());
}
}
for (field, _) in PROFILE_LISTS {
let list: Vec<Json> = node.many(field).iter().map(|x| Json::Obj(x.props.clone())).collect();
if !list.is_empty() {
company = company.with(field, list);
}
}
company
}