use std::collections::BTreeMap;
use crate::admin::store::{Circuit, Service};
use crate::rest_api::paging::Paging;
#[derive(Debug, Serialize, Clone, PartialEq)]
pub(crate) struct ListCircuitsResponse<'a> {
pub data: Vec<CircuitResponse<'a>>,
pub paging: Paging,
}
#[derive(Debug, Serialize, Clone, PartialEq)]
pub(crate) struct CircuitResponse<'a> {
pub id: &'a str,
pub members: Vec<String>,
pub roster: Vec<ServiceResponse<'a>>,
pub management_type: &'a str,
}
impl<'a> From<&'a Circuit> for CircuitResponse<'a> {
fn from(circuit: &'a Circuit) -> Self {
Self {
id: circuit.circuit_id(),
members: circuit
.members()
.iter()
.map(|node| node.node_id().to_string())
.collect(),
roster: circuit.roster().iter().map(ServiceResponse::from).collect(),
management_type: circuit.circuit_management_type(),
}
}
}
#[derive(Debug, Serialize, Clone, PartialEq)]
pub(crate) struct ServiceResponse<'a> {
pub service_id: &'a str,
pub service_type: &'a str,
pub allowed_nodes: Vec<String>,
pub arguments: BTreeMap<String, String>,
}
impl<'a> From<&'a Service> for ServiceResponse<'a> {
fn from(service_def: &'a Service) -> Self {
Self {
service_id: service_def.service_id(),
service_type: service_def.service_type(),
allowed_nodes: vec![service_def.node_id().to_string()],
arguments: service_def
.arguments()
.iter()
.map(|(key, value)| (key.to_string(), value.to_string()))
.collect::<BTreeMap<String, String>>(),
}
}
}