main
use std::collections::BTreeMap;
use crate::gateway::action;
/// 订阅表达式:topic → `tag1 || tag2 ...`,与投递端共用同一份目录。
pub fn plan(prefixes: &[String]) -> BTreeMap<String, String> {
let mut topics: BTreeMap<String, Vec<&'static str>> = BTreeMap::new();
for (prefix, area, tag) in action::catalog() {
if !prefixes.iter().any(|configured| configured == prefix) {
continue;
}
let tags = topics.entry(format!("{prefix}-{area}")).or_default();
if !tags.contains(&tag) {
tags.push(tag);
}
}
topics
.into_iter()
.map(|(topic, tags)| (topic, tags.join(" || ")))
.collect()
}