use crate::errors::Result;
use crate::types::*;
use uuid::Uuid;
use std::fmt::Debug;
pub trait TDBackgroundType: Debug + RObject {}
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[serde(tag = "@type")]
pub enum BackgroundType {
#[doc(hidden)]
#[default]
_Default,
#[serde(rename = "backgroundTypeFill")]
Fill(BackgroundTypeFill),
#[serde(rename = "backgroundTypePattern")]
Pattern(BackgroundTypePattern),
#[serde(rename = "backgroundTypeWallpaper")]
Wallpaper(BackgroundTypeWallpaper),
}
impl RObject for BackgroundType {
#[doc(hidden)]
fn extra(&self) -> Option<&str> {
match self {
BackgroundType::Fill(t) => t.extra(),
BackgroundType::Pattern(t) => t.extra(),
BackgroundType::Wallpaper(t) => t.extra(),
_ => None,
}
}
#[doc(hidden)]
fn client_id(&self) -> Option<i32> {
match self {
BackgroundType::Fill(t) => t.client_id(),
BackgroundType::Pattern(t) => t.client_id(),
BackgroundType::Wallpaper(t) => t.client_id(),
_ => None,
}
}
}
impl BackgroundType {
pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
#[doc(hidden)]
pub fn _is_default(&self) -> bool {
matches!(self, BackgroundType::_Default)
}
}
impl AsRef<BackgroundType> for BackgroundType {
fn as_ref(&self) -> &BackgroundType {
self
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BackgroundTypeFill {
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
#[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
client_id: Option<i32>,
#[serde(skip_serializing_if = "BackgroundFill::_is_default")]
fill: BackgroundFill,
}
impl RObject for BackgroundTypeFill {
#[doc(hidden)]
fn extra(&self) -> Option<&str> {
self.extra.as_deref()
}
#[doc(hidden)]
fn client_id(&self) -> Option<i32> {
self.client_id
}
}
impl TDBackgroundType for BackgroundTypeFill {}
impl BackgroundTypeFill {
pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
pub fn builder() -> BackgroundTypeFillBuilder {
let mut inner = BackgroundTypeFill::default();
inner.extra = Some(Uuid::new_v4().to_string());
BackgroundTypeFillBuilder { inner }
}
pub fn fill(&self) -> &BackgroundFill {
&self.fill
}
}
#[doc(hidden)]
pub struct BackgroundTypeFillBuilder {
inner: BackgroundTypeFill,
}
#[deprecated]
pub type RTDBackgroundTypeFillBuilder = BackgroundTypeFillBuilder;
impl BackgroundTypeFillBuilder {
pub fn build(&self) -> BackgroundTypeFill {
self.inner.clone()
}
pub fn fill<T: AsRef<BackgroundFill>>(&mut self, fill: T) -> &mut Self {
self.inner.fill = fill.as_ref().clone();
self
}
}
impl AsRef<BackgroundTypeFill> for BackgroundTypeFill {
fn as_ref(&self) -> &BackgroundTypeFill {
self
}
}
impl AsRef<BackgroundTypeFill> for BackgroundTypeFillBuilder {
fn as_ref(&self) -> &BackgroundTypeFill {
&self.inner
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BackgroundTypePattern {
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
#[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
client_id: Option<i32>,
#[serde(skip_serializing_if = "BackgroundFill::_is_default")]
fill: BackgroundFill,
#[serde(default)]
intensity: i32,
#[serde(default)]
is_inverted: bool,
#[serde(default)]
is_moving: bool,
}
impl RObject for BackgroundTypePattern {
#[doc(hidden)]
fn extra(&self) -> Option<&str> {
self.extra.as_deref()
}
#[doc(hidden)]
fn client_id(&self) -> Option<i32> {
self.client_id
}
}
impl TDBackgroundType for BackgroundTypePattern {}
impl BackgroundTypePattern {
pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
pub fn builder() -> BackgroundTypePatternBuilder {
let mut inner = BackgroundTypePattern::default();
inner.extra = Some(Uuid::new_v4().to_string());
BackgroundTypePatternBuilder { inner }
}
pub fn fill(&self) -> &BackgroundFill {
&self.fill
}
pub fn intensity(&self) -> i32 {
self.intensity
}
pub fn is_inverted(&self) -> bool {
self.is_inverted
}
pub fn is_moving(&self) -> bool {
self.is_moving
}
}
#[doc(hidden)]
pub struct BackgroundTypePatternBuilder {
inner: BackgroundTypePattern,
}
#[deprecated]
pub type RTDBackgroundTypePatternBuilder = BackgroundTypePatternBuilder;
impl BackgroundTypePatternBuilder {
pub fn build(&self) -> BackgroundTypePattern {
self.inner.clone()
}
pub fn fill<T: AsRef<BackgroundFill>>(&mut self, fill: T) -> &mut Self {
self.inner.fill = fill.as_ref().clone();
self
}
pub fn intensity(&mut self, intensity: i32) -> &mut Self {
self.inner.intensity = intensity;
self
}
pub fn is_inverted(&mut self, is_inverted: bool) -> &mut Self {
self.inner.is_inverted = is_inverted;
self
}
pub fn is_moving(&mut self, is_moving: bool) -> &mut Self {
self.inner.is_moving = is_moving;
self
}
}
impl AsRef<BackgroundTypePattern> for BackgroundTypePattern {
fn as_ref(&self) -> &BackgroundTypePattern {
self
}
}
impl AsRef<BackgroundTypePattern> for BackgroundTypePatternBuilder {
fn as_ref(&self) -> &BackgroundTypePattern {
&self.inner
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BackgroundTypeWallpaper {
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
#[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
client_id: Option<i32>,
#[serde(default)]
is_blurred: bool,
#[serde(default)]
is_moving: bool,
}
impl RObject for BackgroundTypeWallpaper {
#[doc(hidden)]
fn extra(&self) -> Option<&str> {
self.extra.as_deref()
}
#[doc(hidden)]
fn client_id(&self) -> Option<i32> {
self.client_id
}
}
impl TDBackgroundType for BackgroundTypeWallpaper {}
impl BackgroundTypeWallpaper {
pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
pub fn builder() -> BackgroundTypeWallpaperBuilder {
let mut inner = BackgroundTypeWallpaper::default();
inner.extra = Some(Uuid::new_v4().to_string());
BackgroundTypeWallpaperBuilder { inner }
}
pub fn is_blurred(&self) -> bool {
self.is_blurred
}
pub fn is_moving(&self) -> bool {
self.is_moving
}
}
#[doc(hidden)]
pub struct BackgroundTypeWallpaperBuilder {
inner: BackgroundTypeWallpaper,
}
#[deprecated]
pub type RTDBackgroundTypeWallpaperBuilder = BackgroundTypeWallpaperBuilder;
impl BackgroundTypeWallpaperBuilder {
pub fn build(&self) -> BackgroundTypeWallpaper {
self.inner.clone()
}
pub fn is_blurred(&mut self, is_blurred: bool) -> &mut Self {
self.inner.is_blurred = is_blurred;
self
}
pub fn is_moving(&mut self, is_moving: bool) -> &mut Self {
self.inner.is_moving = is_moving;
self
}
}
impl AsRef<BackgroundTypeWallpaper> for BackgroundTypeWallpaper {
fn as_ref(&self) -> &BackgroundTypeWallpaper {
self
}
}
impl AsRef<BackgroundTypeWallpaper> for BackgroundTypeWallpaperBuilder {
fn as_ref(&self) -> &BackgroundTypeWallpaper {
&self.inner
}
}