use chrono::NaiveDateTime;
use indexmap::IndexMap;
use uuid::Uuid;
use crate::db::{Color, CustomDataItem, CustomIcon};
#[derive(Debug, Default, Eq, PartialEq, Clone)]
#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
pub struct Meta {
pub generator: Option<String>,
pub database_name: Option<String>,
pub database_name_changed: Option<NaiveDateTime>,
pub database_description: Option<String>,
pub database_description_changed: Option<NaiveDateTime>,
pub(crate) custom_icons: IndexMap<Uuid, CustomIcon>,
pub default_username: Option<String>,
pub default_username_changed: Option<NaiveDateTime>,
pub maintenance_history_days: Option<usize>,
pub color: Option<Color>,
pub master_key_changed: Option<NaiveDateTime>,
pub master_key_change_rec: Option<isize>,
pub master_key_change_force: Option<isize>,
pub memory_protection: Option<MemoryProtection>,
pub(crate) recyclebin_enabled: Option<bool>,
pub(crate) recyclebin_uuid: Option<Uuid>,
pub(crate) recyclebin_changed: Option<NaiveDateTime>,
pub entry_templates_group: Option<Uuid>,
pub entry_templates_group_changed: Option<NaiveDateTime>,
pub last_selected_group: Option<Uuid>,
pub last_top_visible_group: Option<Uuid>,
pub history_max_items: Option<isize>,
pub history_max_size: Option<isize>,
pub settings_changed: Option<NaiveDateTime>,
pub custom_data: IndexMap<String, CustomDataItem>,
}
impl Meta {
pub fn new() -> Self {
Self {
recyclebin_enabled: Some(true),
..Meta::default()
}
}
pub fn custom_icon(&self, uuid: Uuid) -> Option<&CustomIcon> {
self.custom_icons.get(&uuid)
}
pub fn insert_custom_icon(&mut self, icon: CustomIcon) -> Option<CustomIcon> {
self.custom_icons.insert(icon.id(), icon)
}
pub fn set_recycle_bin_enabled(&mut self, enabled: bool) {
self.recyclebin_enabled = Some(enabled);
self.set_recycle_bin_changed();
}
pub fn recycle_bin_enabled(&self) -> bool {
self.recyclebin_enabled.unwrap_or(false)
}
pub fn recycle_bin_changed(&self) -> Option<NaiveDateTime> {
self.recyclebin_changed
}
pub fn set_recycle_bin_changed(&mut self) {
let time = chrono::Local::now().naive_local();
self.recyclebin_changed = Some(time);
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
pub struct MemoryProtection {
pub protect_title: bool,
pub protect_username: bool,
pub protect_password: bool,
pub protect_url: bool,
pub protect_notes: bool,
}
impl Default for MemoryProtection {
fn default() -> Self {
Self {
protect_title: false,
protect_username: false,
protect_password: true,
protect_url: false,
protect_notes: false,
}
}
}