use crate::actions::verbs;
use crate::ui_state::UiState;
use super::super::reply::Reply;
use super::super::{answer, control};
use super::{Deps, prepare};
pub(super) fn spend(
verb: fn(
&crate::cli_outbound::Cli,
&std::path::Path,
&str,
&std::path::Path,
&str,
&str,
) -> std::io::Result<verbs::Outcome>,
deps: &Deps,
ts: &str,
project: &std::path::Path,
id: &str,
name: &str,
) -> Result<Reply, String> {
outcome(verb(&deps.bl, &deps.state_root, ts, project, id, name))
}
pub(super) fn staged(
deps: &Deps,
ts: &str,
workspace: &std::path::Path,
repo: &std::path::Path,
payload: &crate::start::Payload,
) -> Result<Reply, String> {
prepare(deps, ts, workspace, repo, payload).map(Reply::Prepared)
}
pub(super) fn outcome(ran: std::io::Result<verbs::Outcome>) -> Result<Reply, String> {
ran.map(Reply::Outcome).map_err(|e| e.to_string())
}
pub(super) fn wrote(written: std::io::Result<()>, reply: Reply) -> Result<Reply, String> {
written.map(|()| reply).map_err(|e| e.to_string())
}
pub(super) fn retarget(
deps: &Deps,
ts: &str,
workspace: &std::path::Path,
agent: &str,
) -> std::io::Result<verbs::Outcome> {
verbs::retarget(&deps.bound(workspace), &deps.state_root, ts, agent)
}
pub(super) fn fork(
deps: &Deps,
ts: &str,
workspace: &std::path::Path,
parent: &str,
attempt: &crate::fork::Attempt,
goal: &str,
) -> Result<Reply, String> {
control::confinement_gate(workspace)?;
verbs::fork(
&deps.bound(workspace),
&deps.state_root,
ts,
&crate::fork::Fire::at(workspace, parent, attempt, goal, &deps.yog_data_root),
)
.map(Reply::Outcome)
.map_err(|e| e.to_string())
}
pub(super) fn acknowledge(
deps: &Deps,
ui: &mut UiState,
ts: &str,
workspace: &std::path::Path,
agent: &str,
) -> Result<Reply, String> {
answer::queue::mark_seen(&deps.snapshot, ui, workspace, agent)?;
let rows = answer::queue::queue(&deps.snapshot, ui, ts.parse().unwrap_or(0));
Ok(Reply::Attention(rows))
}