use super::{Acting, Owes, Seat};
use crate::AppModel;
use crate::actions::DraftKey;
use crate::boundary::Action;
use crate::shell::ShellState;
use crate::start::{Prepared, StartInputs};
use std::path::Path;
pub(in crate::shell) fn prepare(
model: &mut AppModel,
state: &mut ShellState,
inputs: &StartInputs,
) {
staging(model, state, inputs, Seat::Quiet, None);
}
pub(in crate::shell) fn fire(
model: &mut AppModel,
state: &mut ShellState,
inputs: &StartInputs,
key: &DraftKey,
text: &str,
) {
staging(
model,
state,
inputs,
Seat::Draft(key.clone()),
Some(text.to_owned()),
);
}
fn staging(
model: &mut AppModel,
state: &mut ShellState,
inputs: &StartInputs,
seat: Seat,
goal: Option<String>,
) {
let action = Action::Prepare {
workspace: model.snap.ws_name(&inputs.workspace),
payload: inputs.payload.clone(),
};
super::hold(
model,
state,
&inputs.workspace,
&action,
seat,
Owes::Prepared { goal },
);
}
pub(in crate::shell) fn prompt(
model: &mut AppModel,
state: &mut ShellState,
ws: &Path,
prepared: &Prepared,
goal: &str,
) {
post(model, state, ws, prepared, goal, Seat::Quiet);
}
fn post(
model: &mut AppModel,
state: &mut ShellState,
ws: &Path,
prepared: &Prepared,
goal: &str,
seat: Seat,
) {
let action = Action::Prompt {
prepared: prepared.clone(),
goal: goal.to_owned(),
seed: Some(state.start.mint_seed),
};
super::hold(
model,
state,
ws,
&action,
seat,
Owes::Started {
goal: goal.to_owned(),
},
);
}
pub(super) fn staged(
model: &mut AppModel,
state: &mut ShellState,
acting: &Acting,
prepared: &Prepared,
goal: Option<String>,
) -> bool {
model.adopt_workspace(&acting.ws);
let Some(text) = goal else {
if crate::actions::goal_present(&prepared.goal) {
state.start.pending = Some(prepared.clone());
} else {
crate::shell::focus::request(state);
}
return false;
};
post(
model,
state,
&acting.ws,
prepared,
&text,
acting.seat.clone(),
);
true
}
pub(super) fn fired(
model: &mut AppModel,
state: &mut ShellState,
ws: &Path,
conversation: &str,
goal: &str,
) {
state.start.spend_mint();
if state.start.pending.take().is_some() {
crate::shell::focus::request(state);
}
model.await_conversation(ws, conversation, goal);
}