use std::collections::HashMap;
use crate::contracts::{ContractSchemaState, RetrievedContract, SuppliedClaim, SuppliedContract};
pub(super) fn supplied_contracts(
contracts: &[RetrievedContract],
name_of: &HashMap<String, String>,
) -> Vec<SuppliedContract> {
contracts
.iter()
.map(|contract| {
let profile = name_of
.get(contract.object.profile().as_str())
.cloned()
.unwrap_or_default();
SuppliedContract {
profile,
object: contract.object.qualified_name(),
schema_state: schema_state_token(contract.schema_state),
claims: contract
.claims
.iter()
.map(|claim| {
let (column, value) = super::render::claim_value(&claim.value);
SuppliedClaim {
claim_id: claim.id.clone(),
kind: claim.value.kind(),
value,
column,
status: claim.status,
}
})
.collect(),
}
})
.collect()
}
fn schema_state_token(state: ContractSchemaState) -> &'static str {
use ContractSchemaState as S;
match state {
S::Current => "current",
S::NeedsReview => "needs_review",
S::LiveSchemaUnavailable => "live_schema_unavailable",
S::Stale => "stale",
}
}