use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use serde::Serialize;
use crate::{
api::API,
entities::{chat_permissions::ChatPermissions, misc::chat_id::ChatId},
errors::ConogramError,
impl_into_future,
request::RequestT,
utils::deserialize_utils::is_false,
};
#[derive(Debug, Clone, Serialize)]
pub struct RestrictChatMemberParams {
pub chat_id: ChatId,
pub user_id: i64,
pub permissions: ChatPermissions,
#[serde(default, skip_serializing_if = "is_false")]
pub use_independent_chat_permissions: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub until_date: Option<i64>,
}
impl_into_future!(RestrictChatMemberRequest<'a>);
#[derive(Clone)]
pub struct RestrictChatMemberRequest<'a> {
api: &'a API,
params: RestrictChatMemberParams,
}
impl<'a> RequestT for RestrictChatMemberRequest<'a> {
type ParamsType = RestrictChatMemberParams;
type ReturnType = bool;
fn get_name() -> &'static str {
"restrictChatMember"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
false
}
}
impl<'a> RestrictChatMemberRequest<'a> {
pub fn new(
api: &'a API,
chat_id: impl Into<ChatId>,
user_id: impl Into<i64>,
permissions: impl Into<ChatPermissions>,
) -> Self {
Self {
api,
params: RestrictChatMemberParams {
chat_id: chat_id.into(),
user_id: user_id.into(),
permissions: permissions.into(),
use_independent_chat_permissions: bool::default(),
until_date: 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 user_id(mut self, user_id: impl Into<i64>) -> Self {
self.params.user_id = user_id.into();
self
}
#[must_use]
pub fn permissions(mut self, permissions: impl Into<ChatPermissions>) -> Self {
self.params.permissions = permissions.into();
self
}
#[must_use]
pub fn use_independent_chat_permissions(
mut self,
use_independent_chat_permissions: impl Into<bool>,
) -> Self {
self.params.use_independent_chat_permissions = use_independent_chat_permissions.into();
self
}
#[must_use]
pub fn until_date(mut self, until_date: impl Into<i64>) -> Self {
self.params.until_date = Some(until_date.into());
self
}
}
impl API {
pub fn restrict_chat_member(
&self,
chat_id: impl Into<ChatId>,
user_id: impl Into<i64>,
permissions: impl Into<ChatPermissions>,
) -> RestrictChatMemberRequest {
RestrictChatMemberRequest::new(self, chat_id, user_id, permissions)
}
}