use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use serde::Serialize;
use crate::{
api::API,
entities::{chat_invite_link::ChatInviteLink, misc::chat_id::ChatId},
errors::ConogramError,
impl_into_future,
request::RequestT,
utils::deserialize_utils::is_false,
};
#[derive(Debug, Clone, Serialize)]
pub struct CreateChatInviteLinkParams {
pub chat_id: ChatId,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expire_date: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub member_limit: Option<i64>,
#[serde(default, skip_serializing_if = "is_false")]
pub creates_join_request: bool,
}
impl_into_future!(CreateChatInviteLinkRequest<'a>);
#[derive(Clone)]
pub struct CreateChatInviteLinkRequest<'a> {
api: &'a API,
params: CreateChatInviteLinkParams,
}
impl<'a> RequestT for CreateChatInviteLinkRequest<'a> {
type ParamsType = CreateChatInviteLinkParams;
type ReturnType = ChatInviteLink;
fn get_name() -> &'static str {
"createChatInviteLink"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
false
}
}
impl<'a> CreateChatInviteLinkRequest<'a> {
pub fn new(api: &'a API, chat_id: impl Into<ChatId>) -> Self {
Self {
api,
params: CreateChatInviteLinkParams {
chat_id: chat_id.into(),
name: Option::default(),
expire_date: Option::default(),
member_limit: Option::default(),
creates_join_request: bool::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 = Some(name.into());
self
}
#[must_use]
pub fn expire_date(mut self, expire_date: impl Into<i64>) -> Self {
self.params.expire_date = Some(expire_date.into());
self
}
#[must_use]
pub fn member_limit(mut self, member_limit: impl Into<i64>) -> Self {
self.params.member_limit = Some(member_limit.into());
self
}
#[must_use]
pub fn creates_join_request(mut self, creates_join_request: impl Into<bool>) -> Self {
self.params.creates_join_request = creates_join_request.into();
self
}
}
impl API {
pub fn create_chat_invite_link(
&self,
chat_id: impl Into<ChatId>,
) -> CreateChatInviteLinkRequest {
CreateChatInviteLinkRequest::new(self, chat_id)
}
}