use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use serde::Serialize;
use crate::{
api::API,
entities::{forum_topic::ForumTopic, misc::chat_id::ChatId},
errors::ConogramError,
impl_into_future,
request::RequestT,
};
#[derive(Debug, Clone, Serialize)]
pub struct CreateForumTopicParams {
pub chat_id: ChatId,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub icon_color: Option<CreateForumTopicIconColor>,
#[serde(skip_serializing_if = "Option::is_none")]
pub icon_custom_emoji_id: Option<String>,
}
impl_into_future!(CreateForumTopicRequest<'a>);
#[derive(Clone)]
pub struct CreateForumTopicRequest<'a> {
api: &'a API,
params: CreateForumTopicParams,
}
impl<'a> RequestT for CreateForumTopicRequest<'a> {
type ParamsType = CreateForumTopicParams;
type ReturnType = ForumTopic;
fn get_name() -> &'static str {
"createForumTopic"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
false
}
}
impl<'a> CreateForumTopicRequest<'a> {
pub fn new(api: &'a API, chat_id: impl Into<ChatId>, name: impl Into<String>) -> Self {
Self {
api,
params: CreateForumTopicParams {
chat_id: chat_id.into(),
name: name.into(),
icon_color: Option::default(),
icon_custom_emoji_id: Option::default(),
},
}
}
#[must_use]
pub fn chat_id(mut self, chat_id: impl Into<ChatId>) -> Self {
self.params.chat_id = chat_id.into();
self
}
#[must_use]
pub fn name(mut self, name: impl Into<String>) -> Self {
self.params.name = name.into();
self
}
#[must_use]
pub fn icon_color(mut self, icon_color: impl Into<CreateForumTopicIconColor>) -> Self {
self.params.icon_color = Some(icon_color.into());
self
}
#[must_use]
pub fn icon_custom_emoji_id(mut self, icon_custom_emoji_id: impl Into<String>) -> Self {
self.params.icon_custom_emoji_id = Some(icon_custom_emoji_id.into());
self
}
}
impl API {
pub fn create_forum_topic(
&self,
chat_id: impl Into<ChatId>,
name: impl Into<String>,
) -> CreateForumTopicRequest {
CreateForumTopicRequest::new(self, chat_id, name)
}
}
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
#[serde(rename = "icon_color")]
pub enum CreateForumTopicIconColor {
#[default]
_6FB9F0 = 0x6fb9f0,
_FFD67E = 0xffd67e,
_CB86DB = 0xcb86db,
_8EEE98 = 0x8eee98,
_FF93B2 = 0xff93b2,
_FB6F5F = 0xfb6f5f,
}