use crate::errors::*;
use crate::types::*;
use uuid::Uuid;
use serde::de::{Deserialize, Deserializer};
use std::fmt::Debug;
pub trait TDChatStatistics: Debug + RObject {}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum ChatStatistics {
#[doc(hidden)]
_Default(()),
Channel(ChatStatisticsChannel),
Supergroup(ChatStatisticsSupergroup),
GetChatStatistics(GetChatStatistics),
}
impl Default for ChatStatistics {
fn default() -> Self {
ChatStatistics::_Default(())
}
}
impl<'de> Deserialize<'de> for ChatStatistics {
fn deserialize<D>(deserializer: D) -> Result<ChatStatistics, D::Error>
where
D: Deserializer<'de>,
{
use serde::de::Error;
rtd_enum_deserialize!(
ChatStatistics,
(chatStatisticsChannel, Channel);
(chatStatisticsSupergroup, Supergroup);
(getChatStatistics, GetChatStatistics);
)(deserializer)
}
}
impl RObject for ChatStatistics {
#[doc(hidden)]
fn td_name(&self) -> &'static str {
match self {
ChatStatistics::Channel(t) => t.td_name(),
ChatStatistics::Supergroup(t) => t.td_name(),
ChatStatistics::GetChatStatistics(t) => t.td_name(),
_ => "-1",
}
}
#[doc(hidden)]
fn extra(&self) -> Option<String> {
match self {
ChatStatistics::Channel(t) => t.extra(),
ChatStatistics::Supergroup(t) => t.extra(),
ChatStatistics::GetChatStatistics(t) => t.extra(),
_ => None,
}
}
fn to_json(&self) -> RTDResult<String> {
Ok(serde_json::to_string(self)?)
}
}
impl ChatStatistics {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
#[doc(hidden)]
pub fn _is_default(&self) -> bool {
matches!(self, ChatStatistics::_Default(_))
}
pub fn is_channel(&self) -> bool {
matches!(self, ChatStatistics::Channel(_))
}
pub fn is_supergroup(&self) -> bool {
matches!(self, ChatStatistics::Supergroup(_))
}
pub fn is_get_chat_statistics(&self) -> bool {
matches!(self, ChatStatistics::GetChatStatistics(_))
}
pub fn on_channel<F: FnOnce(&ChatStatisticsChannel)>(&self, fnc: F) -> &Self {
if let ChatStatistics::Channel(t) = self {
fnc(t)
};
self
}
pub fn on_supergroup<F: FnOnce(&ChatStatisticsSupergroup)>(&self, fnc: F) -> &Self {
if let ChatStatistics::Supergroup(t) = self {
fnc(t)
};
self
}
pub fn on_get_chat_statistics<F: FnOnce(&GetChatStatistics)>(&self, fnc: F) -> &Self {
if let ChatStatistics::GetChatStatistics(t) = self {
fnc(t)
};
self
}
pub fn as_channel(&self) -> Option<&ChatStatisticsChannel> {
if let ChatStatistics::Channel(t) = self {
return Some(t);
}
None
}
pub fn as_supergroup(&self) -> Option<&ChatStatisticsSupergroup> {
if let ChatStatistics::Supergroup(t) = self {
return Some(t);
}
None
}
pub fn as_get_chat_statistics(&self) -> Option<&GetChatStatistics> {
if let ChatStatistics::GetChatStatistics(t) = self {
return Some(t);
}
None
}
pub fn channel<T: AsRef<ChatStatisticsChannel>>(t: T) -> Self {
ChatStatistics::Channel(t.as_ref().clone())
}
pub fn supergroup<T: AsRef<ChatStatisticsSupergroup>>(t: T) -> Self {
ChatStatistics::Supergroup(t.as_ref().clone())
}
pub fn get_chat_statistics<T: AsRef<GetChatStatistics>>(t: T) -> Self {
ChatStatistics::GetChatStatistics(t.as_ref().clone())
}
}
impl AsRef<ChatStatistics> for ChatStatistics {
fn as_ref(&self) -> &ChatStatistics {
self
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ChatStatisticsChannel {
#[doc(hidden)]
#[serde(rename(serialize = "@type", deserialize = "@type"))]
td_name: String,
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
period: DateRange,
member_count: StatisticalValue,
mean_message_view_count: StatisticalValue,
mean_message_share_count: StatisticalValue,
mean_message_reaction_count: StatisticalValue,
mean_story_view_count: StatisticalValue,
mean_story_share_count: StatisticalValue,
mean_story_reaction_count: StatisticalValue,
enabled_notifications_percentage: f32,
member_count_graph: StatisticalGraph,
join_graph: StatisticalGraph,
mute_graph: StatisticalGraph,
view_count_by_hour_graph: StatisticalGraph,
view_count_by_source_graph: StatisticalGraph,
join_by_source_graph: StatisticalGraph,
language_graph: StatisticalGraph,
message_interaction_graph: StatisticalGraph,
message_reaction_graph: StatisticalGraph,
story_interaction_graph: StatisticalGraph,
story_reaction_graph: StatisticalGraph,
instant_view_interaction_graph: StatisticalGraph,
recent_interactions: Vec<ChatStatisticsInteractionInfo>,
}
impl RObject for ChatStatisticsChannel {
#[doc(hidden)]
fn td_name(&self) -> &'static str {
"chatStatisticsChannel"
}
#[doc(hidden)]
fn extra(&self) -> Option<String> {
self.extra.clone()
}
fn to_json(&self) -> RTDResult<String> {
Ok(serde_json::to_string(self)?)
}
}
impl TDChatStatistics for ChatStatisticsChannel {}
impl ChatStatisticsChannel {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
pub fn builder() -> RTDChatStatisticsChannelBuilder {
let inner = ChatStatisticsChannel {
td_name: "chatStatisticsChannel".to_string(),
extra: Some(Uuid::new_v4().to_string()),
..Default::default()
};
RTDChatStatisticsChannelBuilder { inner }
}
pub fn period(&self) -> &DateRange {
&self.period
}
pub fn member_count(&self) -> &StatisticalValue {
&self.member_count
}
pub fn mean_message_view_count(&self) -> &StatisticalValue {
&self.mean_message_view_count
}
pub fn mean_message_share_count(&self) -> &StatisticalValue {
&self.mean_message_share_count
}
pub fn mean_message_reaction_count(&self) -> &StatisticalValue {
&self.mean_message_reaction_count
}
pub fn mean_story_view_count(&self) -> &StatisticalValue {
&self.mean_story_view_count
}
pub fn mean_story_share_count(&self) -> &StatisticalValue {
&self.mean_story_share_count
}
pub fn mean_story_reaction_count(&self) -> &StatisticalValue {
&self.mean_story_reaction_count
}
pub fn enabled_notifications_percentage(&self) -> f32 {
self.enabled_notifications_percentage
}
pub fn member_count_graph(&self) -> &StatisticalGraph {
&self.member_count_graph
}
pub fn join_graph(&self) -> &StatisticalGraph {
&self.join_graph
}
pub fn mute_graph(&self) -> &StatisticalGraph {
&self.mute_graph
}
pub fn view_count_by_hour_graph(&self) -> &StatisticalGraph {
&self.view_count_by_hour_graph
}
pub fn view_count_by_source_graph(&self) -> &StatisticalGraph {
&self.view_count_by_source_graph
}
pub fn join_by_source_graph(&self) -> &StatisticalGraph {
&self.join_by_source_graph
}
pub fn language_graph(&self) -> &StatisticalGraph {
&self.language_graph
}
pub fn message_interaction_graph(&self) -> &StatisticalGraph {
&self.message_interaction_graph
}
pub fn message_reaction_graph(&self) -> &StatisticalGraph {
&self.message_reaction_graph
}
pub fn story_interaction_graph(&self) -> &StatisticalGraph {
&self.story_interaction_graph
}
pub fn story_reaction_graph(&self) -> &StatisticalGraph {
&self.story_reaction_graph
}
pub fn instant_view_interaction_graph(&self) -> &StatisticalGraph {
&self.instant_view_interaction_graph
}
pub fn recent_interactions(&self) -> &Vec<ChatStatisticsInteractionInfo> {
&self.recent_interactions
}
}
#[doc(hidden)]
pub struct RTDChatStatisticsChannelBuilder {
inner: ChatStatisticsChannel,
}
impl RTDChatStatisticsChannelBuilder {
pub fn build(&self) -> ChatStatisticsChannel {
self.inner.clone()
}
pub fn period<T: AsRef<DateRange>>(&mut self, period: T) -> &mut Self {
self.inner.period = period.as_ref().clone();
self
}
pub fn member_count<T: AsRef<StatisticalValue>>(&mut self, member_count: T) -> &mut Self {
self.inner.member_count = member_count.as_ref().clone();
self
}
pub fn mean_message_view_count<T: AsRef<StatisticalValue>>(
&mut self,
mean_message_view_count: T,
) -> &mut Self {
self.inner.mean_message_view_count = mean_message_view_count.as_ref().clone();
self
}
pub fn mean_message_share_count<T: AsRef<StatisticalValue>>(
&mut self,
mean_message_share_count: T,
) -> &mut Self {
self.inner.mean_message_share_count = mean_message_share_count.as_ref().clone();
self
}
pub fn mean_message_reaction_count<T: AsRef<StatisticalValue>>(
&mut self,
mean_message_reaction_count: T,
) -> &mut Self {
self.inner.mean_message_reaction_count = mean_message_reaction_count.as_ref().clone();
self
}
pub fn mean_story_view_count<T: AsRef<StatisticalValue>>(
&mut self,
mean_story_view_count: T,
) -> &mut Self {
self.inner.mean_story_view_count = mean_story_view_count.as_ref().clone();
self
}
pub fn mean_story_share_count<T: AsRef<StatisticalValue>>(
&mut self,
mean_story_share_count: T,
) -> &mut Self {
self.inner.mean_story_share_count = mean_story_share_count.as_ref().clone();
self
}
pub fn mean_story_reaction_count<T: AsRef<StatisticalValue>>(
&mut self,
mean_story_reaction_count: T,
) -> &mut Self {
self.inner.mean_story_reaction_count = mean_story_reaction_count.as_ref().clone();
self
}
pub fn enabled_notifications_percentage(
&mut self,
enabled_notifications_percentage: f32,
) -> &mut Self {
self.inner.enabled_notifications_percentage = enabled_notifications_percentage;
self
}
pub fn member_count_graph<T: AsRef<StatisticalGraph>>(
&mut self,
member_count_graph: T,
) -> &mut Self {
self.inner.member_count_graph = member_count_graph.as_ref().clone();
self
}
pub fn join_graph<T: AsRef<StatisticalGraph>>(&mut self, join_graph: T) -> &mut Self {
self.inner.join_graph = join_graph.as_ref().clone();
self
}
pub fn mute_graph<T: AsRef<StatisticalGraph>>(&mut self, mute_graph: T) -> &mut Self {
self.inner.mute_graph = mute_graph.as_ref().clone();
self
}
pub fn view_count_by_hour_graph<T: AsRef<StatisticalGraph>>(
&mut self,
view_count_by_hour_graph: T,
) -> &mut Self {
self.inner.view_count_by_hour_graph = view_count_by_hour_graph.as_ref().clone();
self
}
pub fn view_count_by_source_graph<T: AsRef<StatisticalGraph>>(
&mut self,
view_count_by_source_graph: T,
) -> &mut Self {
self.inner.view_count_by_source_graph = view_count_by_source_graph.as_ref().clone();
self
}
pub fn join_by_source_graph<T: AsRef<StatisticalGraph>>(
&mut self,
join_by_source_graph: T,
) -> &mut Self {
self.inner.join_by_source_graph = join_by_source_graph.as_ref().clone();
self
}
pub fn language_graph<T: AsRef<StatisticalGraph>>(&mut self, language_graph: T) -> &mut Self {
self.inner.language_graph = language_graph.as_ref().clone();
self
}
pub fn message_interaction_graph<T: AsRef<StatisticalGraph>>(
&mut self,
message_interaction_graph: T,
) -> &mut Self {
self.inner.message_interaction_graph = message_interaction_graph.as_ref().clone();
self
}
pub fn message_reaction_graph<T: AsRef<StatisticalGraph>>(
&mut self,
message_reaction_graph: T,
) -> &mut Self {
self.inner.message_reaction_graph = message_reaction_graph.as_ref().clone();
self
}
pub fn story_interaction_graph<T: AsRef<StatisticalGraph>>(
&mut self,
story_interaction_graph: T,
) -> &mut Self {
self.inner.story_interaction_graph = story_interaction_graph.as_ref().clone();
self
}
pub fn story_reaction_graph<T: AsRef<StatisticalGraph>>(
&mut self,
story_reaction_graph: T,
) -> &mut Self {
self.inner.story_reaction_graph = story_reaction_graph.as_ref().clone();
self
}
pub fn instant_view_interaction_graph<T: AsRef<StatisticalGraph>>(
&mut self,
instant_view_interaction_graph: T,
) -> &mut Self {
self.inner.instant_view_interaction_graph = instant_view_interaction_graph.as_ref().clone();
self
}
pub fn recent_interactions(
&mut self,
recent_interactions: Vec<ChatStatisticsInteractionInfo>,
) -> &mut Self {
self.inner.recent_interactions = recent_interactions;
self
}
}
impl AsRef<ChatStatisticsChannel> for ChatStatisticsChannel {
fn as_ref(&self) -> &ChatStatisticsChannel {
self
}
}
impl AsRef<ChatStatisticsChannel> for RTDChatStatisticsChannelBuilder {
fn as_ref(&self) -> &ChatStatisticsChannel {
&self.inner
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ChatStatisticsSupergroup {
#[doc(hidden)]
#[serde(rename(serialize = "@type", deserialize = "@type"))]
td_name: String,
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
period: DateRange,
member_count: StatisticalValue,
message_count: StatisticalValue,
viewer_count: StatisticalValue,
sender_count: StatisticalValue,
member_count_graph: StatisticalGraph,
join_graph: StatisticalGraph,
join_by_source_graph: StatisticalGraph,
language_graph: StatisticalGraph,
message_content_graph: StatisticalGraph,
action_graph: StatisticalGraph,
day_graph: StatisticalGraph,
week_graph: StatisticalGraph,
top_senders: Vec<ChatStatisticsMessageSenderInfo>,
top_administrators: Vec<ChatStatisticsAdministratorActionsInfo>,
top_inviters: Vec<ChatStatisticsInviterInfo>,
}
impl RObject for ChatStatisticsSupergroup {
#[doc(hidden)]
fn td_name(&self) -> &'static str {
"chatStatisticsSupergroup"
}
#[doc(hidden)]
fn extra(&self) -> Option<String> {
self.extra.clone()
}
fn to_json(&self) -> RTDResult<String> {
Ok(serde_json::to_string(self)?)
}
}
impl TDChatStatistics for ChatStatisticsSupergroup {}
impl ChatStatisticsSupergroup {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
pub fn builder() -> RTDChatStatisticsSupergroupBuilder {
let inner = ChatStatisticsSupergroup {
td_name: "chatStatisticsSupergroup".to_string(),
extra: Some(Uuid::new_v4().to_string()),
..Default::default()
};
RTDChatStatisticsSupergroupBuilder { inner }
}
pub fn period(&self) -> &DateRange {
&self.period
}
pub fn member_count(&self) -> &StatisticalValue {
&self.member_count
}
pub fn message_count(&self) -> &StatisticalValue {
&self.message_count
}
pub fn viewer_count(&self) -> &StatisticalValue {
&self.viewer_count
}
pub fn sender_count(&self) -> &StatisticalValue {
&self.sender_count
}
pub fn member_count_graph(&self) -> &StatisticalGraph {
&self.member_count_graph
}
pub fn join_graph(&self) -> &StatisticalGraph {
&self.join_graph
}
pub fn join_by_source_graph(&self) -> &StatisticalGraph {
&self.join_by_source_graph
}
pub fn language_graph(&self) -> &StatisticalGraph {
&self.language_graph
}
pub fn message_content_graph(&self) -> &StatisticalGraph {
&self.message_content_graph
}
pub fn action_graph(&self) -> &StatisticalGraph {
&self.action_graph
}
pub fn day_graph(&self) -> &StatisticalGraph {
&self.day_graph
}
pub fn week_graph(&self) -> &StatisticalGraph {
&self.week_graph
}
pub fn top_senders(&self) -> &Vec<ChatStatisticsMessageSenderInfo> {
&self.top_senders
}
pub fn top_administrators(&self) -> &Vec<ChatStatisticsAdministratorActionsInfo> {
&self.top_administrators
}
pub fn top_inviters(&self) -> &Vec<ChatStatisticsInviterInfo> {
&self.top_inviters
}
}
#[doc(hidden)]
pub struct RTDChatStatisticsSupergroupBuilder {
inner: ChatStatisticsSupergroup,
}
impl RTDChatStatisticsSupergroupBuilder {
pub fn build(&self) -> ChatStatisticsSupergroup {
self.inner.clone()
}
pub fn period<T: AsRef<DateRange>>(&mut self, period: T) -> &mut Self {
self.inner.period = period.as_ref().clone();
self
}
pub fn member_count<T: AsRef<StatisticalValue>>(&mut self, member_count: T) -> &mut Self {
self.inner.member_count = member_count.as_ref().clone();
self
}
pub fn message_count<T: AsRef<StatisticalValue>>(&mut self, message_count: T) -> &mut Self {
self.inner.message_count = message_count.as_ref().clone();
self
}
pub fn viewer_count<T: AsRef<StatisticalValue>>(&mut self, viewer_count: T) -> &mut Self {
self.inner.viewer_count = viewer_count.as_ref().clone();
self
}
pub fn sender_count<T: AsRef<StatisticalValue>>(&mut self, sender_count: T) -> &mut Self {
self.inner.sender_count = sender_count.as_ref().clone();
self
}
pub fn member_count_graph<T: AsRef<StatisticalGraph>>(
&mut self,
member_count_graph: T,
) -> &mut Self {
self.inner.member_count_graph = member_count_graph.as_ref().clone();
self
}
pub fn join_graph<T: AsRef<StatisticalGraph>>(&mut self, join_graph: T) -> &mut Self {
self.inner.join_graph = join_graph.as_ref().clone();
self
}
pub fn join_by_source_graph<T: AsRef<StatisticalGraph>>(
&mut self,
join_by_source_graph: T,
) -> &mut Self {
self.inner.join_by_source_graph = join_by_source_graph.as_ref().clone();
self
}
pub fn language_graph<T: AsRef<StatisticalGraph>>(&mut self, language_graph: T) -> &mut Self {
self.inner.language_graph = language_graph.as_ref().clone();
self
}
pub fn message_content_graph<T: AsRef<StatisticalGraph>>(
&mut self,
message_content_graph: T,
) -> &mut Self {
self.inner.message_content_graph = message_content_graph.as_ref().clone();
self
}
pub fn action_graph<T: AsRef<StatisticalGraph>>(&mut self, action_graph: T) -> &mut Self {
self.inner.action_graph = action_graph.as_ref().clone();
self
}
pub fn day_graph<T: AsRef<StatisticalGraph>>(&mut self, day_graph: T) -> &mut Self {
self.inner.day_graph = day_graph.as_ref().clone();
self
}
pub fn week_graph<T: AsRef<StatisticalGraph>>(&mut self, week_graph: T) -> &mut Self {
self.inner.week_graph = week_graph.as_ref().clone();
self
}
pub fn top_senders(&mut self, top_senders: Vec<ChatStatisticsMessageSenderInfo>) -> &mut Self {
self.inner.top_senders = top_senders;
self
}
pub fn top_administrators(
&mut self,
top_administrators: Vec<ChatStatisticsAdministratorActionsInfo>,
) -> &mut Self {
self.inner.top_administrators = top_administrators;
self
}
pub fn top_inviters(&mut self, top_inviters: Vec<ChatStatisticsInviterInfo>) -> &mut Self {
self.inner.top_inviters = top_inviters;
self
}
}
impl AsRef<ChatStatisticsSupergroup> for ChatStatisticsSupergroup {
fn as_ref(&self) -> &ChatStatisticsSupergroup {
self
}
}
impl AsRef<ChatStatisticsSupergroup> for RTDChatStatisticsSupergroupBuilder {
fn as_ref(&self) -> &ChatStatisticsSupergroup {
&self.inner
}
}