use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use serde::Serialize;
use crate::{
api::API,
entities::{
inline_query_result::InlineQueryResult,
inline_query_results_button::InlineQueryResultsButton,
},
errors::ConogramError,
impl_into_future,
request::RequestT,
utils::deserialize_utils::is_false,
};
#[derive(Debug, Clone, Serialize)]
pub struct AnswerInlineQueryParams {
pub inline_query_id: String,
pub results: Vec<InlineQueryResult>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cache_time: Option<i64>,
#[serde(default, skip_serializing_if = "is_false")]
pub is_personal: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub next_offset: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub button: Option<InlineQueryResultsButton>,
}
impl_into_future!(AnswerInlineQueryRequest<'a>);
#[derive(Clone)]
pub struct AnswerInlineQueryRequest<'a> {
api: &'a API,
params: AnswerInlineQueryParams,
}
impl<'a> RequestT for AnswerInlineQueryRequest<'a> {
type ParamsType = AnswerInlineQueryParams;
type ReturnType = bool;
fn get_name() -> &'static str {
"answerInlineQuery"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
false
}
}
impl<'a> AnswerInlineQueryRequest<'a> {
pub fn new(
api: &'a API,
inline_query_id: impl Into<String>,
results: impl IntoIterator<Item = impl Into<InlineQueryResult>>,
) -> Self {
Self {
api,
params: AnswerInlineQueryParams {
inline_query_id: inline_query_id.into(),
results: results.into_iter().map(Into::into).collect(),
cache_time: Option::default(),
is_personal: bool::default(),
next_offset: Option::default(),
button: Option::default(),
},
}
}
#[must_use]
pub fn inline_query_id(mut self, inline_query_id: impl Into<String>) -> Self {
self.params.inline_query_id = inline_query_id.into();
self
}
#[must_use]
pub fn results(
mut self,
results: impl IntoIterator<Item = impl Into<InlineQueryResult>>,
) -> Self {
self.params.results = results.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn cache_time(mut self, cache_time: impl Into<i64>) -> Self {
self.params.cache_time = Some(cache_time.into());
self
}
#[must_use]
pub fn is_personal(mut self, is_personal: impl Into<bool>) -> Self {
self.params.is_personal = is_personal.into();
self
}
#[must_use]
pub fn next_offset(mut self, next_offset: impl Into<String>) -> Self {
self.params.next_offset = Some(next_offset.into());
self
}
#[must_use]
pub fn button(mut self, button: impl Into<InlineQueryResultsButton>) -> Self {
self.params.button = Some(button.into());
self
}
}
impl API {
pub fn answer_inline_query(
&self,
inline_query_id: impl Into<String>,
results: impl IntoIterator<Item = impl Into<InlineQueryResult>>,
) -> AnswerInlineQueryRequest {
AnswerInlineQueryRequest::new(self, inline_query_id, results)
}
}