use crate::model::{Field, FieldKind, Item};
pub fn mk_field(name: &str, value: &str, kind: FieldKind) -> Field {
let protected = matches!(kind, FieldKind::Secret | FieldKind::Totp);
Field {
name: name.into(),
value: value.into(),
kind,
protected,
}
}
pub fn mk_item(template_id: &str, title: &str, fields: &[(&str, &str, FieldKind)]) -> Item {
Item {
id: None,
template_id: template_id.into(),
title: title.into(),
category_id: None,
fields: fields
.iter()
.map(|(n, v, k)| mk_field(n, v, *k))
.collect(),
favorite: false,
tags: Vec::new(),
created_at: 0,
updated_at: 0,
}
}
pub fn mk_password_item(username: &str, password: &str) -> Item {
mk_item(
"password",
"",
&[
("username", username, FieldKind::Text),
("password", password, FieldKind::Secret),
("url", "", FieldKind::Text),
("totp", "", FieldKind::Totp),
("notes", "", FieldKind::Multiline),
],
)
}