use crate::reply::balls::BallRow;
use crate::reply::board::{BoardRow, Fleet};
use crate::reply::spend::Figure;
pub fn headline(row: &BoardRow) -> String {
format!("{} {}", row.id, row.title)
}
pub fn placed(row: &BoardRow) -> String {
format!(
"{} · {} priority {} in {}",
row.column, row.state, row.priority, row.project
)
}
pub fn held(row: &BoardRow) -> Option<String> {
let mut said: Vec<String> = Vec::new();
if let Some(claimant) = &row.claimant {
said.push(format!("held by {claimant}"));
}
if let Some(workspace) = &row.workspace {
said.push(format!("on {workspace}"));
}
if let Some(parent) = &row.parent {
said.push(format!("under {parent}"));
}
(!said.is_empty()).then(|| said.join(" "))
}
pub fn gated(row: &BoardRow) -> Option<String> {
(!row.gates.is_empty()).then(|| {
let by: Vec<String> = row
.gates
.iter()
.map(|gate| format!("{} {} ({})", gate.id, gate.title, gate.mints))
.collect();
format!("gated by {}", by.join(" "))
})
}
pub fn worked(row: &BoardRow) -> Option<String> {
(!row.drones.is_empty()).then(|| {
let on: Vec<String> = row
.drones
.iter()
.map(|drone| format!("{} ({})", drone.name, drone.root_id))
.collect();
format!("worked by {}", on.join(" "))
})
}
pub fn cost(figure: &Figure) -> String {
let mut said: Vec<String> = Vec::new();
if let Some(usd) = &figure.usd {
said.push(usd.clone());
}
said.push(format!("{} tokens", figure.tokens.total));
said.push(
figure
.attribution
.label
.clone()
.unwrap_or_else(|| figure.attribution.kind.clone()),
);
said.join(" ")
}
pub fn running(loop_: &Fleet) -> String {
let mut said = vec![format!(
"running {} in {}: {}",
loop_.project, loop_.workspace, loop_.label
)];
if !loop_.room {
said.push("full".to_owned());
}
if let Some(ceiling) = &loop_.ceiling {
said.push(format!("ceiling: {ceiling}"));
}
said.join(" ")
}
pub fn binding(row: &BallRow) -> String {
let mut said = vec![row.ball_id.clone()];
if let Some(title) = &row.title {
said.push(title.clone());
}
said.push(format!("[{}]", row.state));
said.push(format!("in {}", row.project));
match (&row.claimant, &row.workspace) {
(Some(claimant), Some(workspace)) => said.push(format!("{claimant} on {workspace}")),
(Some(claimant), None) => said.push(format!("held by {claimant}")),
(None, _) => said.push("unheld".to_owned()),
}
said.join(" ")
}
#[cfg(test)]
mod tests;