use crate::verbs::auth::WSAuth;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "type")]
pub enum Target {
Phone(Phone),
Sip(Sip),
User(User),
Teams(Teams),
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Phone {
pub number: String,
#[serde(rename = "confirmHook")]
#[serde(skip_serializing_if = "Option::is_none")]
pub confirm_hook: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub trunk: Option<String>,
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub headers: HashMap<String, String>,
}
impl Into<Target> for Phone {
fn into(self) -> Target {
Target::Phone(self)
}
}
impl Into<Vec<Target>> for Phone {
fn into(self) -> Vec<Target> {
vec![self.into()]
}
}
impl Phone {
pub fn new(number: String) -> Phone {
Phone {
number,
confirm_hook: None,
trunk: None,
headers: HashMap::new(),
}
}
pub fn confirm_hook(&mut self, confirm_hook: Option<String>) -> &mut Phone {
self.confirm_hook = confirm_hook;
self
}
pub fn trunk(&mut self, trunk: Option<String>) -> &mut Phone {
self.trunk = trunk;
self
}
pub fn header(&mut self, key: String, value: String) -> &mut Phone {
self.headers.insert(key.to_string(), value);
self
}
pub fn replace_headers(&mut self, headers: HashMap<String, String>) -> &mut Phone {
self.headers = headers;
self
}
pub fn add_headers(&mut self, headers: HashMap<String, String>) -> &mut Phone {
self.headers.extend(headers);
self
}
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Sip {
#[serde(rename = "sipUri")]
pub sip_uri: String,
#[serde(rename = "confirmHook")]
#[serde(skip_serializing_if = "Option::is_none")]
pub confirm_hook: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub auth: Option<WSAuth>,
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub headers: HashMap<String, String>,
}
impl Into<Target> for Sip {
fn into(self) -> Target {
Target::Sip(self)
}
}
impl Into<Vec<Target>> for Sip {
fn into(self) -> Vec<Target> {
vec![self.into()]
}
}
impl Sip {
pub fn new(sip_uri: String) -> Sip {
Sip {
sip_uri,
confirm_hook: None,
auth: None,
headers: HashMap::new(),
}
}
pub fn from_parts(phone_number: String, ip_address: String, port: u16) -> Sip {
Sip {
sip_uri: format!("sip:{}@{}:{}", phone_number, ip_address, port),
confirm_hook: None,
auth: None,
headers: HashMap::new(),
}
}
pub fn confirm_hook(&mut self, confirm_hook: Option<String>) -> &mut Sip {
self.confirm_hook = confirm_hook;
self
}
pub fn auth(&mut self, auth: Option<WSAuth>) -> &mut Sip {
self.auth = auth;
self
}
pub fn header(&mut self, key: String, value: String) -> &mut Sip {
self.headers.insert(key, value);
self
}
pub fn replace_headers(&mut self, headers: HashMap<String, String>) -> &mut Sip {
self.headers = headers;
self
}
pub fn add_headers(&mut self, headers: HashMap<String, String>) -> &mut Sip {
self.headers.extend(headers);
self
}
}
#[derive(Serialize, Deserialize, Clone)]
pub struct User {
pub name: String,
#[serde(rename = "confirmHook")]
#[serde(skip_serializing_if = "Option::is_none")]
pub confirm_hook: Option<String>,
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub headers: HashMap<String, String>,
#[serde(rename = "overrideTo")]
#[serde(skip_serializing_if = "Option::is_none")]
pub override_to: Option<String>,
}
impl Into<Target> for User {
fn into(self) -> Target {
Target::User(self)
}
}
impl Into<Vec<Target>> for User {
fn into(self) -> Vec<Target> {
vec![self.into()]
}
}
impl User {
pub fn new(name: String) -> User {
User {
name,
confirm_hook: None,
override_to: None,
headers: HashMap::new(),
}
}
pub fn from_parts(username: String, domain: String) -> User {
User {
name: format!("{}@{}", username, domain),
confirm_hook: None,
override_to: None,
headers: HashMap::new(),
}
}
pub fn confirm_hook(&mut self, confirm_hook: Option<String>) -> &mut User {
self.confirm_hook = confirm_hook;
self
}
pub fn override_to(&mut self, override_to: Option<String>) -> &mut User {
self.override_to = override_to;
self
}
pub fn header(&mut self, key: String, value: String) -> &mut User {
self.headers.insert(key, value);
self
}
pub fn replace_headers(&mut self, headers: HashMap<String, String>) -> &mut User {
self.headers = headers;
self
}
pub fn add_headers(&mut self, headers: HashMap<String, String>) -> &mut User {
self.headers.extend(headers);
self
}
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Teams {
pub number: String,
#[serde(rename = "confirmHook")]
#[serde(skip_serializing_if = "Option::is_none")]
pub confirm_hook: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tenant: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub voicemail: Option<bool>,
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub headers: HashMap<String, String>,
}
impl Into<Target> for Teams {
fn into(self) -> Target {
Target::Teams(self)
}
}
impl Into<Vec<Target>> for Teams {
fn into(self) -> Vec<Target> {
vec![self.into()]
}
}
impl Teams {
pub fn new(number: String) -> Teams {
Teams {
number,
confirm_hook: None,
tenant: None,
voicemail: None,
headers: HashMap::new(),
}
}
pub fn from_parts(number: String, tenant: Option<String>) -> Teams {
Teams {
number,
tenant,
confirm_hook: None,
voicemail: None,
headers: HashMap::new(),
}
}
pub fn tenant(&mut self, tenant: Option<String>) -> &mut Teams {
self.tenant = tenant;
self
}
pub fn voicemail(&mut self, vm: Option<bool>) -> &mut Teams {
self.voicemail = vm;
self
}
pub fn confirm_hook(&mut self, confirm_hook: Option<String>) -> &mut Teams {
self.confirm_hook = confirm_hook;
self
}
pub fn header(&mut self, key: String, value: String) -> &mut Teams {
self.headers.insert(key.to_string(), value.to_string());
self
}
pub fn replace_headers(&mut self, headers: HashMap<String, String>) -> &mut Teams {
self.headers = headers;
self
}
pub fn add_headers(&mut self, headers: HashMap<String, String>) -> &mut Teams {
self.headers.extend(headers);
self
}
}