use serde_json::{Map, Value};
use super::fields;
pub(crate) const KIND: &str = "inbox";
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Row {
pub name: String,
pub raw: String,
pub deposit: Deposit,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Deposit {
pub from: Option<String>,
pub deposited_at: Option<String>,
pub epitaph: Option<String>,
pub terminal_ref: Option<String>,
pub body: String,
}
pub(crate) fn row(value: &Value) -> Result<Row, String> {
let obj: &Map<String, Value> = value.as_object().ok_or("inbox row: not an object")?;
Ok(Row {
name: fields::text(obj, "name")?,
raw: fields::text(obj, "raw")?,
deposit: fields::object(obj, "deposit", deposit)?,
})
}
fn deposit(obj: &Map<String, Value>) -> Result<Deposit, String> {
Ok(Deposit {
from: fields::opt_text(obj, "from")?,
deposited_at: fields::opt_text(obj, "deposited_at")?,
epitaph: fields::opt_text(obj, "epitaph")?,
terminal_ref: fields::opt_text(obj, "terminal_ref")?,
body: fields::text(obj, "body")?,
})
}
#[cfg(test)]
mod tests;