use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use serde::Serialize;
use crate::{
api::API,
entities::{
inline_query_result::InlineQueryResult, prepared_inline_message::PreparedInlineMessage,
},
errors::ConogramError,
impl_into_future,
request::RequestT,
utils::deserialize_utils::is_false,
};
#[derive(Debug, Clone, Serialize)]
pub struct SavePreparedInlineMessageParams {
pub user_id: i64,
pub result: InlineQueryResult,
#[serde(default, skip_serializing_if = "is_false")]
pub allow_user_chats: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub allow_bot_chats: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub allow_group_chats: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub allow_channel_chats: bool,
}
impl_into_future!(SavePreparedInlineMessageRequest<'a>);
#[derive(Clone)]
pub struct SavePreparedInlineMessageRequest<'a> {
api: &'a API,
params: SavePreparedInlineMessageParams,
}
impl<'a> RequestT for SavePreparedInlineMessageRequest<'a> {
type ParamsType = SavePreparedInlineMessageParams;
type ReturnType = PreparedInlineMessage;
fn get_name() -> &'static str {
"savePreparedInlineMessage"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
false
}
}
impl<'a> SavePreparedInlineMessageRequest<'a> {
pub fn new(
api: &'a API,
user_id: impl Into<i64>,
result: impl Into<InlineQueryResult>,
) -> Self {
Self {
api,
params: SavePreparedInlineMessageParams {
user_id: user_id.into(),
result: result.into(),
allow_user_chats: bool::default(),
allow_bot_chats: bool::default(),
allow_group_chats: bool::default(),
allow_channel_chats: bool::default(),
},
}
}
#[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 result(mut self, result: impl Into<InlineQueryResult>) -> Self {
self.params.result = result.into();
self
}
#[must_use]
pub fn allow_user_chats(mut self, allow_user_chats: impl Into<bool>) -> Self {
self.params.allow_user_chats = allow_user_chats.into();
self
}
#[must_use]
pub fn allow_bot_chats(mut self, allow_bot_chats: impl Into<bool>) -> Self {
self.params.allow_bot_chats = allow_bot_chats.into();
self
}
#[must_use]
pub fn allow_group_chats(mut self, allow_group_chats: impl Into<bool>) -> Self {
self.params.allow_group_chats = allow_group_chats.into();
self
}
#[must_use]
pub fn allow_channel_chats(mut self, allow_channel_chats: impl Into<bool>) -> Self {
self.params.allow_channel_chats = allow_channel_chats.into();
self
}
}
impl API {
pub fn save_prepared_inline_message(
&self,
user_id: impl Into<i64>,
result: impl Into<InlineQueryResult>,
) -> SavePreparedInlineMessageRequest {
SavePreparedInlineMessageRequest::new(self, user_id, result)
}
}