use teloxide::types::*;
use super::MockUser;
use crate::proc_macros::Changeable;
macro_rules! Chat {
(
#[derive($($derive:meta),*)]
$pub:vis struct $name:ident {
$($fpub:vis $field:ident : $type:ty,)*
}
) => {
#[derive($($derive),*)]
$pub struct $name { // This is basically a template
pub id: ChatId,
$($fpub $field : $type,)*
}
impl $name {
pub const ID: i64 = -12345678;
pub(crate) fn new_chat($($field:$type,)*) -> Self {
Self { id: ChatId(Self::ID),
$($field,)*
}
}
pub(crate) fn build_chat(self, chat_kind: ChatKind) -> Chat {
Chat {
id: self.id,
kind: chat_kind,
}
}
}
}
}
macro_rules! ChatPublic { (
#[derive($($derive:meta),*)]
$pub:vis struct $name:ident {
$($fpub:vis $field:ident : $type:ty,)*
}
) => {
Chat! {
#[derive($($derive),*)]
$pub struct $name {
pub title: Option<String>,
$($fpub $field : $type,)*
}
}
impl $name {
pub(crate) fn new_chat_public($($field:$type,)*) -> Self {
$name::new_chat(
None,
$($field,)*
)
}
pub(crate) fn build_chat_public(self, chat_public_kind: PublicChatKind) -> Chat {
self.clone().build_chat(ChatKind::Public(ChatPublic {
title: self.title,
kind: chat_public_kind,
}))
}
}
}
}
ChatPublic! {
#[derive(Changeable, Clone)]
pub struct MockGroupChat { }
}
impl MockGroupChat {
pub fn new() -> Self {
Self::new_chat_public()
}
pub fn build(self) -> Chat {
self.clone().build_chat_public(PublicChatKind::Group)
}
}
ChatPublic! {
#[derive(Changeable, Clone)]
pub struct MockChannelChat {
pub username: Option<String>,
}
}
impl MockChannelChat {
pub fn new() -> Self {
Self::new_chat_public(None)
}
pub fn build(self) -> Chat {
self.clone()
.build_chat_public(PublicChatKind::Channel(PublicChatChannel {
username: self.username,
}))
}
}
ChatPublic! {
#[derive(Changeable, Clone)]
pub struct MockSupergroupChat {
pub username: Option<String>,
pub is_forum: bool,
}
}
impl MockSupergroupChat {
pub const IS_FORUM: bool = false;
pub fn new() -> Self {
Self::new_chat_public(None, Self::IS_FORUM)
}
pub fn build(self) -> Chat {
self.clone()
.build_chat_public(PublicChatKind::Supergroup(PublicChatSupergroup {
username: self.username,
is_forum: self.is_forum,
}))
}
}
Chat! {
#[derive(Changeable, Clone)]
pub struct MockPrivateChat {
pub username: Option<String>,
pub first_name: Option<String>,
pub last_name: Option<String>,
}
}
impl MockPrivateChat {
pub fn new() -> Self {
Self::new_chat(None, None, None).id(MockUser::ID as i64)
}
pub fn build(self) -> Chat {
self.clone().build_chat(ChatKind::Private(ChatPrivate {
username: self.username,
first_name: self.first_name,
last_name: self.last_name,
}))
}
}