//! THE FACE A TABLE WEARS, READ FOR ONE TABLE: the database's face choices//! (`face_choices`, keyed by its `row_key`) as `shell.opened`'s Face step,//! `shell.input`'s commit and a dealt card (`records.get`, `records.list`)//! read them. A deck reads every table's at once (`shell_deck::read_held`).usesuper::catalogue::FaceChoiceTable;usecrate::methods::MethodError;usecrate::shell::client::ClientController;use cotton_core::definitions::TableDefinition;use serde_json::{json, Map, Value};/// The table a database keeps its face choices in, and the choice made for/// one table (none yet: an empty `chosen`).pub(crate) structChoices {pub table: FaceChoiceTable,pub chosen: Map<String, Value>,}/// Every table definition the database holds.pub(crate) fn tables(client: &ClientController, method: &str) -> Result<Vec<TableDefinition>, MethodError> {letmut tables = Vec::new(); client .read_rows(method, &mut |ctx| { tables = cotton_tools::definitions::table_definitions(ctx).map_err(|failure| failure.to_string())?.definitions;Ok(Value::Null) }) .map_err(|why| MethodError::new("unreadable", why))?;Ok(tables)}/// `table`'s choice; None where the database keeps no face choices.pub(crate) fn of(client: &ClientController, table: &str, method: &str) -> Result<Option<Choices>, MethodError> {letSome(choices) = FaceChoiceTable::of(&tables(client, method)?) else { returnOk(None) };let asked = json!({ "table": choices.table, "where": { (choices.row_key.as_str()): table } });let listed = super::records::call(client, "records.list", &asked)?;letmut chosen = Map::new();ifletSome(face) = listed["records"].as_array().into_iter().flatten().find_map(|row| row["data"]["face"].as_str()) { chosen.insert(table.to_string(), json!(face)); }Ok(Some(Choices { table: choices, chosen }))}