use crate::client::BotClient;
use crate::error::Result;
use rustigram_types::user::ChatId;
use serde::Serialize;
use std::future::{Future, IntoFuture};
use std::pin::Pin;
#[derive(Serialize)]
struct VerifyUserParams {
user_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
custom_description: Option<String>,
}
pub struct VerifyUser {
client: BotClient,
params: VerifyUserParams,
}
impl VerifyUser {
pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
Self {
client,
params: VerifyUserParams {
user_id,
custom_description: None,
},
}
}
pub fn custom_description(mut self, d: impl Into<String>) -> Self {
self.params.custom_description = Some(d.into());
self
}
}
impl IntoFuture for VerifyUser {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move { self.client.post_json("verifyUser", &self.params).await })
}
}
#[derive(Serialize)]
struct VerifyChatParams {
chat_id: ChatId,
#[serde(skip_serializing_if = "Option::is_none")]
custom_description: Option<String>,
}
pub struct VerifyChat {
client: BotClient,
params: VerifyChatParams,
}
impl VerifyChat {
pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
Self {
client,
params: VerifyChatParams {
chat_id: chat_id.into(),
custom_description: None,
},
}
}
pub fn custom_description(mut self, d: impl Into<String>) -> Self {
self.params.custom_description = Some(d.into());
self
}
}
impl IntoFuture for VerifyChat {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move { self.client.post_json("verifyChat", &self.params).await })
}
}
#[derive(Serialize)]
struct RemoveUserVerificationParams {
user_id: i64,
}
pub struct RemoveUserVerification {
client: BotClient,
params: RemoveUserVerificationParams,
}
impl RemoveUserVerification {
pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
Self {
client,
params: RemoveUserVerificationParams { user_id },
}
}
}
impl IntoFuture for RemoveUserVerification {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("removeUserVerification", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct RemoveChatVerificationParams {
chat_id: ChatId,
}
pub struct RemoveChatVerification {
client: BotClient,
params: RemoveChatVerificationParams,
}
impl RemoveChatVerification {
pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
Self {
client,
params: RemoveChatVerificationParams {
chat_id: chat_id.into(),
},
}
}
}
impl IntoFuture for RemoveChatVerification {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("removeChatVerification", &self.params)
.await
})
}
}