use std::collections::HashMap;
use jmap_types::{impl_string_enum, Id, UTCDate};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum NodeType {
File,
Directory,
Symlink,
Other(String),
}
impl_string_enum!(NodeType, "a JMAP FileNode type string",
"file" => File,
"directory" => Directory,
"symlink" => Symlink,
);
impl NodeType {
pub fn to_wire_str(&self) -> &str {
match self {
Self::File => "file",
Self::Directory => "directory",
Self::Symlink => "symlink",
Self::Other(s) => s.as_str(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum NodeRole {
Root,
Home,
Temp,
Trash,
Documents,
Downloads,
Music,
Pictures,
Videos,
Other(String),
}
impl_string_enum!(NodeRole, "a JMAP FileNode role string",
"root" => Root,
"home" => Home,
"temp" => Temp,
"trash" => Trash,
"documents" => Documents,
"downloads" => Downloads,
"music" => Music,
"pictures" => Pictures,
"videos" => Videos,
);
impl NodeRole {
pub fn to_wire_str(&self) -> &str {
match self {
Self::Root => "root",
Self::Home => "home",
Self::Temp => "temp",
Self::Trash => "trash",
Self::Documents => "documents",
Self::Downloads => "downloads",
Self::Music => "music",
Self::Pictures => "pictures",
Self::Videos => "videos",
Self::Other(s) => s.as_str(),
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FilesRights {
pub may_read: bool,
pub may_add_children: bool,
pub may_rename: bool,
pub may_delete: bool,
pub may_modify_content: bool,
pub may_share: bool,
#[serde(flatten, default, skip_serializing_if = "serde_json::Map::is_empty")]
pub extra: serde_json::Map<String, serde_json::Value>,
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FileNode {
pub id: Id,
pub parent_id: Option<Id>,
#[serde(skip_serializing_if = "Option::is_none")]
pub node_type: Option<NodeType>,
pub blob_id: Option<Id>,
pub target: Option<Vec<String>>,
pub size: Option<u64>,
pub name: String,
#[serde(rename = "type")]
pub media_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<UTCDate>,
#[serde(skip_serializing_if = "Option::is_none")]
pub modified: Option<UTCDate>,
#[serde(skip_serializing_if = "Option::is_none")]
pub accessed: Option<UTCDate>,
#[serde(skip_serializing_if = "Option::is_none")]
pub changed: Option<UTCDate>,
#[serde(skip_serializing_if = "Option::is_none")]
pub executable: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_subscribed: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub my_rights: Option<FilesRights>,
pub share_with: Option<HashMap<Id, FilesRights>>,
pub role: Option<NodeRole>,
#[serde(flatten, default, skip_serializing_if = "serde_json::Map::is_empty")]
pub extra: serde_json::Map<String, serde_json::Value>,
}