use serde_json::{Map, Value};
use super::super::Reply;
use crate::boundary::codec::fields::{opt_str_of, opt_val, str_of, strings_of, usize_of};
pub(super) fn decode(kind: &str, o: &Map<String, Value>) -> Option<Result<Reply, String>> {
Some(match kind {
"transcript" => crate::transcript::wire::decode::transcript(o).map(Reply::Transcript),
super::super::encode::FOLLOW => follow(o),
"steps" => crate::steps_view::wire::decode::steps(o).map(Reply::Steps),
"step" => crate::steps_view::wire::decode::detail(o).map(Reply::Step),
"files" => files(o),
"rail" => crate::rail::wire::rail_of(o).map(Reply::Rail),
"governing" => governing(o),
"inbox" => crate::inboxview::wire::entries_of(o).map(Reply::Inbox),
"agent" => super::super::agent::view_of(o).map(Reply::Agent),
"work-diff" => work_diff(o),
"science" => crate::science::wire::rows_of(o).map(Reply::Science),
_ => return None,
})
}
fn follow(o: &Map<String, Value>) -> Result<Reply, String> {
super::super::follow_frame::frame_of(o).map(Reply::Follow)
}
fn files(o: &Map<String, Value>) -> Result<Reply, String> {
Ok(Reply::Files {
view: crate::files_view::wire::view_of(o)?,
preview: opt_val(o, "preview", crate::files_view::wire::preview_of)?,
working_dir: crate::files_view::wire::working_dir_of(o)?,
})
}
fn governing(o: &Map<String, Value>) -> Result<Reply, String> {
use crate::config_edit::branch::Governance;
let governance = match opt_str_of(o, "follows")? {
Some(branch) => Governance::Follows(branch),
None => Governance::Held {
diverged_lineages: usize_of(o, "diverged_lineages")?,
},
};
Ok(Reply::Governing {
config: crate::config_edit::branch::GoverningConfig {
oid: str_of(o, "oid")?,
short_oid: str_of(o, "short_oid")?,
governance,
files: strings_of(o, "files")?,
},
workflow_mark: opt_val(o, "workflow_mark", super::super::workflow::mark_of)?,
})
}
fn work_diff(o: &Map<String, Value>) -> Result<Reply, String> {
Ok(Reply::WorkDiff {
attempts: crate::workdiff::wire::attempts_of(o)?,
patch: opt_val(o, "patch", crate::files_view::wire::preview_of)?,
})
}