use crate::errors::*;
use crate::types::*;
use uuid::Uuid;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ThemeSettings {
#[doc(hidden)]
#[serde(rename(serialize = "@type", deserialize = "@type"))]
td_name: String,
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
base_theme: BuiltInTheme,
accent_color: i64,
background: Option<Background>,
outgoing_message_fill: Option<BackgroundFill>,
animate_outgoing_message_fill: bool,
has_outgoing_message_accent_color: bool,
outgoing_message_accent_color: i64,
}
impl RObject for ThemeSettings {
#[doc(hidden)]
fn td_name(&self) -> &'static str {
"themeSettings"
}
#[doc(hidden)]
fn extra(&self) -> Option<String> {
self.extra.clone()
}
fn to_json(&self) -> RTDResult<String> {
Ok(serde_json::to_string(self)?)
}
}
impl ThemeSettings {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
pub fn builder() -> RTDThemeSettingsBuilder {
let inner = ThemeSettings {
td_name: "themeSettings".to_string(),
extra: Some(Uuid::new_v4().to_string()),
..Default::default()
};
RTDThemeSettingsBuilder { inner }
}
pub fn base_theme(&self) -> &BuiltInTheme {
&self.base_theme
}
pub fn accent_color(&self) -> i64 {
self.accent_color
}
pub fn background(&self) -> &Option<Background> {
&self.background
}
pub fn outgoing_message_fill(&self) -> &Option<BackgroundFill> {
&self.outgoing_message_fill
}
pub fn animate_outgoing_message_fill(&self) -> bool {
self.animate_outgoing_message_fill
}
pub fn has_outgoing_message_accent_color(&self) -> bool {
self.has_outgoing_message_accent_color
}
pub fn outgoing_message_accent_color(&self) -> i64 {
self.outgoing_message_accent_color
}
}
#[doc(hidden)]
pub struct RTDThemeSettingsBuilder {
inner: ThemeSettings,
}
impl RTDThemeSettingsBuilder {
pub fn build(&self) -> ThemeSettings {
self.inner.clone()
}
pub fn base_theme<T: AsRef<BuiltInTheme>>(&mut self, base_theme: T) -> &mut Self {
self.inner.base_theme = base_theme.as_ref().clone();
self
}
pub fn accent_color(&mut self, accent_color: i64) -> &mut Self {
self.inner.accent_color = accent_color;
self
}
pub fn background<T: AsRef<Background>>(&mut self, background: T) -> &mut Self {
self.inner.background = Some(background.as_ref().clone());
self
}
pub fn outgoing_message_fill<T: AsRef<BackgroundFill>>(
&mut self,
outgoing_message_fill: T,
) -> &mut Self {
self.inner.outgoing_message_fill = Some(outgoing_message_fill.as_ref().clone());
self
}
pub fn animate_outgoing_message_fill(
&mut self,
animate_outgoing_message_fill: bool,
) -> &mut Self {
self.inner.animate_outgoing_message_fill = animate_outgoing_message_fill;
self
}
pub fn has_outgoing_message_accent_color(
&mut self,
has_outgoing_message_accent_color: bool,
) -> &mut Self {
self.inner.has_outgoing_message_accent_color = has_outgoing_message_accent_color;
self
}
pub fn outgoing_message_accent_color(&mut self, outgoing_message_accent_color: i64) -> &mut Self {
self.inner.outgoing_message_accent_color = outgoing_message_accent_color;
self
}
}
impl AsRef<ThemeSettings> for ThemeSettings {
fn as_ref(&self) -> &ThemeSettings {
self
}
}
impl AsRef<ThemeSettings> for RTDThemeSettingsBuilder {
fn as_ref(&self) -> &ThemeSettings {
&self.inner
}
}