use serde::{Deserialize, Serialize};
use crate::{
api::{Method, Payload, PayloadError},
types::{ChatId, ForumTopicIconColor, Integer, Sticker},
};
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct ForumTopic {
pub icon_color: ForumTopicIconColor,
pub message_thread_id: Integer,
pub name: String,
pub icon_custom_emoji_id: Option<String>,
pub is_name_implicit: Option<bool>,
}
#[derive(Clone, Debug, Serialize)]
pub struct CloseForumTopic {
chat_id: ChatId,
message_thread_id: Integer,
}
impl CloseForumTopic {
pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
where
T: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
message_thread_id,
}
}
}
impl Method for CloseForumTopic {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("closeForumTopic", self)
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct CreateForumTopic {
chat_id: ChatId,
name: String,
icon_color: Option<ForumTopicIconColor>,
icon_custom_emoji_id: Option<String>,
}
impl CreateForumTopic {
pub fn new<A, B>(chat_id: A, name: B) -> Self
where
A: Into<ChatId>,
B: Into<String>,
{
Self {
chat_id: chat_id.into(),
name: name.into(),
icon_color: None,
icon_custom_emoji_id: None,
}
}
pub fn with_icon_color(mut self, value: ForumTopicIconColor) -> Self {
self.icon_color = Some(value);
self
}
pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.icon_custom_emoji_id = Some(value.into());
self
}
}
impl Method for CreateForumTopic {
type Response = ForumTopic;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("createForumTopic", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct CloseGeneralForumTopic {
chat_id: ChatId,
}
impl CloseGeneralForumTopic {
pub fn new<T>(chat_id: T) -> Self
where
T: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
}
}
}
impl Method for CloseGeneralForumTopic {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("closeGeneralForumTopic", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct DeleteForumTopic {
chat_id: ChatId,
message_thread_id: Integer,
}
impl DeleteForumTopic {
pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
where
T: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
message_thread_id,
}
}
}
impl Method for DeleteForumTopic {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("deleteForumTopic", self)
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct EditForumTopic {
chat_id: ChatId,
message_thread_id: Integer,
icon_custom_emoji_id: Option<String>,
name: Option<String>,
}
impl EditForumTopic {
pub fn new<C>(chat_id: C, message_thread_id: Integer) -> Self
where
C: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
message_thread_id,
icon_custom_emoji_id: None,
name: None,
}
}
pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.icon_custom_emoji_id = Some(value.into());
self
}
pub fn with_name<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.name = Some(value.into());
self
}
}
impl Method for EditForumTopic {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("editForumTopic", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct EditGeneralForumTopic {
chat_id: ChatId,
name: String,
}
impl EditGeneralForumTopic {
pub fn new<A, B>(chat_id: A, name: B) -> Self
where
A: Into<ChatId>,
B: Into<String>,
{
Self {
chat_id: chat_id.into(),
name: name.into(),
}
}
}
impl Method for EditGeneralForumTopic {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("editGeneralForumTopic", self)
}
}
#[derive(Clone, Copy, Debug)]
pub struct GetForumTopicIconStickers;
impl Method for GetForumTopicIconStickers {
type Response = Vec<Sticker>;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::empty("getForumTopicIconStickers")
}
}
#[derive(Clone, Debug, Serialize)]
pub struct HideGeneralForumTopic {
chat_id: ChatId,
}
impl HideGeneralForumTopic {
pub fn new<T>(chat_id: T) -> Self
where
T: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
}
}
}
impl Method for HideGeneralForumTopic {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("hideGeneralForumTopic", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct ReopenForumTopic {
chat_id: ChatId,
message_thread_id: Integer,
}
impl ReopenForumTopic {
pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
where
T: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
message_thread_id,
}
}
}
impl Method for ReopenForumTopic {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("reopenForumTopic", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct ReopenGeneralForumTopic {
chat_id: ChatId,
}
impl ReopenGeneralForumTopic {
pub fn new<T>(chat_id: T) -> Self
where
T: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
}
}
}
impl Method for ReopenGeneralForumTopic {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("reopenGeneralForumTopic", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct UnhideGeneralForumTopic {
chat_id: ChatId,
}
impl UnhideGeneralForumTopic {
pub fn new<T>(chat_id: T) -> Self
where
T: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
}
}
}
impl Method for UnhideGeneralForumTopic {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("unhideGeneralForumTopic", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct UnpinAllForumTopicMessages {
chat_id: ChatId,
message_thread_id: Integer,
}
impl UnpinAllForumTopicMessages {
pub fn new<T>(chat_id: T, message_thread_id: Integer) -> Self
where
T: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
message_thread_id,
}
}
}
impl Method for UnpinAllForumTopicMessages {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("unpinAllForumTopicMessages", self)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct UnpinAllGeneralForumTopicMessages {
chat_id: ChatId,
}
impl UnpinAllGeneralForumTopicMessages {
pub fn new<T>(chat_id: T) -> Self
where
T: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),
}
}
}
impl Method for UnpinAllGeneralForumTopicMessages {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("unpinAllGeneralForumTopicMessages", self)
}
}