use std::collections::BTreeMap;
use ruma_identifiers::{RoomAliasId, UserId};
use ruma_serde::StringEnum;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Protocol {
pub user_fields: Vec<String>,
pub location_fields: Vec<String>,
#[cfg_attr(feature = "compat", serde(default))]
pub icon: String,
pub field_types: BTreeMap<String, FieldType>,
pub instances: Vec<ProtocolInstance>,
}
#[derive(Debug)]
pub struct ProtocolInit {
pub user_fields: Vec<String>,
pub location_fields: Vec<String>,
pub icon: String,
pub field_types: BTreeMap<String, FieldType>,
pub instances: Vec<ProtocolInstance>,
}
impl From<ProtocolInit> for Protocol {
fn from(init: ProtocolInit) -> Self {
let ProtocolInit { user_fields, location_fields, icon, field_types, instances } = init;
Self { user_fields, location_fields, icon, field_types, instances }
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct ProtocolInstance {
pub desc: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub icon: Option<String>,
pub fields: BTreeMap<String, String>,
pub network_id: String,
}
#[derive(Debug)]
pub struct ProtocolInstanceInit {
pub desc: String,
pub fields: BTreeMap<String, String>,
pub network_id: String,
}
impl From<ProtocolInstanceInit> for ProtocolInstance {
fn from(init: ProtocolInstanceInit) -> Self {
let ProtocolInstanceInit { desc, fields, network_id } = init;
Self { desc, icon: None, fields, network_id }
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct FieldType {
pub regexp: String,
pub placeholder: String,
}
#[derive(Debug)]
pub struct FieldTypeInit {
pub regexp: String,
pub placeholder: String,
}
impl From<FieldTypeInit> for FieldType {
fn from(init: FieldTypeInit) -> Self {
let FieldTypeInit { regexp, placeholder } = init;
Self { regexp, placeholder }
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Location {
pub alias: RoomAliasId,
pub protocol: String,
pub fields: BTreeMap<String, String>,
}
impl Location {
pub fn new(alias: RoomAliasId, protocol: String, fields: BTreeMap<String, String>) -> Self {
Self { alias, protocol, fields }
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct User {
pub userid: UserId,
pub protocol: String,
pub fields: BTreeMap<String, String>,
}
impl User {
pub fn new(userid: UserId, protocol: String, fields: BTreeMap<String, String>) -> Self {
Self { userid, protocol, fields }
}
}
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "lowercase")]
pub enum Medium {
Email,
Msisdn,
#[doc(hidden)]
_Custom(String),
}